在Vue中使用i18n 国际化遇到 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
最近用Vue在搭建前端框架,在引用i18n时,运行的时候报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>',在此记录下。
先看看代码:安装i18n 插件就不累述了(npm install vue-i18n
)
中文:cn.js
module.exports={ indexText:{
Code:'編號',
}
}
英文:en.js
module.exports={ indexText:{
Code:'Code',
}
}
引用上两个js 中的 main.js
import Vue from 'vue'
import App from './App'
import store from './store/store'
import router from './router'
import VueI18n from 'vue-i18n'
Vue.config.productionTip = false Vue.use(VueI18n)//通过插件的形式挂载 moment.locale('zh-cn'); //设置语言 或 moment.lang('zh-cn');
Vue.prototype.$moment = moment;//赋值使用
const i18n=new VueI18n({
locale:'zh-TCC',
messages:{
'zh-CN':require('./i18n/lang/cn'),
'en-US':require('./i18n/lang/en'),
}
}) new Vue({
el: '#app',
router,
store,
i18n,
render: h => h(App)
}).$mount('#app')
以上代码再运行的时候就会页面一片空白,也不显示任何错误,但我们打开console,可以看到输出报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>',
导致这个错误的原因:在webpack打包的时候,可以在js文件中混用require和export。但是不能混用import 以及module.exports。
在百度到这个原因后,于是整各项目搜索,module.exports,定位到以上代码并做出修改调整,将cn.js 、en.js中的module.export 改成export。
调整中文 cn.js
var MessageCh={ indexText:{
Code:'编号' }
} export{
MessageCh
}
调整英文 en.js
var MessageEn={ indexText:{
Code:'Code' }
} export{
MessageEn
}
调整main.js
import Vue from 'vue'
import App from './App'
import store from './store/store'
import router from './router'
import VueI18n from 'vue-i18n'
import {MessageCh} from './i18n/lang/cn'
import{MessageEn} from './i18n/lang/en'
import{MessageTcc} from './i18n/lang/tcc'
Vue.config.productionTip = false Vue.use(VueI18n)//通过插件的形式挂载 moment.locale('zh-cn'); //设置语言 或 moment.lang('zh-cn');
Vue.prototype.$moment = moment;//赋值使用
const i18n=new VueI18n({
locale:'zh-TCC',
messages:{
'zh-CN':MessageCh,
'en-US':MessageEn,
'zh-TCC':MessageTcc
}
}) new Vue({
el: '#app',
router,
store,
i18n,
render: h => h(App)
}).$mount('#app')
在Vue中使用i18n 国际化遇到 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'的更多相关文章
- Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>' ...
- Vue 使用自定义组件时报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
自己试做了一下vue的插件 参考element-ui: 写了一个组件 import message from './packages/message/index.js'; const install ...
- Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>' 点开错误的文 ...
- Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决方法
发现问题 运行一下以前的一个Vue+webpack的 vue仿新闻网站 小项目,报错 由于自己vue学习不深入,老是这个报错,找了好久(确切的说是整整一下午^...^)才找到原因 -v- Uncau ...
- vue运行报错error:Cannot assign to read only property 'exports' of object '#<Object>'
用weex做项目的时候,npm start 之后一直报错error:Cannot assign to read only property 'exports' of object '#<Obje ...
- vue 项目的I18n国际化之路
I18n (internationalization ) ---未完善 产品国际化是产品后期维护及推广中重要的一环,通过国际化操作使得产品能更好适应不同语言和地区的需求 国际化重点:1. 语言语言本地 ...
- spring中使用i18n(国际化)
简单了解i18n i18n(其来源是英文单词internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称.在资讯领域,国际化(i18n)指让产品(出版物,软件,硬件 ...
- javascript 及 vue 中的变量前面的美元符号 $ 是什么意思
$ 您会注意到,我们将库代理为以美元符号“$”为前缀的属性名. 你可能还看过其他的属性和方法,例如,$refs, $on, $mount等等也都是以”$”开头. 虽然属性名上添加前缀不是必须的,但是这 ...
- 项目中遇到Uncaught TypeError: Converting circular structure to JSON报错问题
最近公司项目中出现一个报错Uncaught TypeError: Converting circular structure to JSON,,根据上述报错可以知道代码是运行到JSON.stringi ...
随机推荐
- 安装PS
1:下载溜云库 2:查找PS软件,下载 3:按照教程安装
- jQuery-文件上传问题解决
后端要求文件上传需传参数为二进制流,用form-data方式传递,如下图所示: 为了满足该输入参数要求,上传代码如下: <input type="file" id=" ...
- Jedis & spring-data-redis
当我们了解了redis的五大数据类型,手动去敲一敲每个数据类型对应的命令,无论是再来看jedis,还是spring-data-redis都是很轻松的,他们提供的API都是基于原生的redis命令,可读 ...
- PAT 1009 Product of Polynomials 模拟
This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: Each ...
- VS2010到VS2019各个版本的密钥
VS2019专业版和企业版的密钥 Visual Studio 2019 EnterpriseBF8Y8-GN2QH-T84XB-QVY3B-RC4DF Visual Studio 2019 Profe ...
- Implement Property Value Validation in the Application Model 在应用程序模型中实现属性值验证
In this lesson, you will learn how to check whether or not a property value satisfies a particular r ...
- easyUI+servlet+mysql项目总结
项目介绍 利用easyUI做前端框架,进行数据展示和用户数据收集 使用servlet做后端的控制层,并调用业务逻辑组件的业务逻辑方法,处理用户请求,根据不同处理结果返回不同的结果到前端 mysql进行 ...
- Linux 内核虚拟地址到物理地址转换讨论【转】
转自:https://blog.csdn.net/sunlei0625/article/details/59476987 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请 ...
- python中copy()和deepcopy()详解
**首先直接上结论: —–我们寻常意义的复制就是深复制,即将被复制对象完全再复制一遍作为独立的新个体单独存在.所以改变原有被复制对象不会对已经复制出来的新对象产生影响.—–而浅复制并不会产生一个独立的 ...
- 2019-2020-1 20199305《Linux内核原理与分析》第三周作业
操作系统的秘密 (一)计算机的三大法宝 存储程序计算机: 函数调用堆栈机制: 中断机制. (二)堆栈 (1)堆栈的作用 记录函数调用框架: 传递函数参数: 保存返回值的地址: 提供局部变量存储空间. ...