在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 ...
随机推荐
- 配置 Elasticsearch 集群
Elasticsearch 的安装非常简单,笔者在前文<单机部署 ELK>中已经介绍过了,本文主要介绍集群的配置,并解释常见配置参数的含义. 要配置集群,最简单的情况下,设置下面几个参数就 ...
- php中对于file的相关语句
// 打开文件 fopen(); // 打开文件的方式 r 只读,r+ 读写方式打开 w 以写入的方式打开 w+ 以读写方式打开(以覆盖的形式写入) // a以写入的方式打开,文件不存在则创建 x创建 ...
- Ubuntu 合上笔记本不会进入休眠模式
首先 sudo vim /etc/systemd/logind.conf 把文件中的 #HandleLidSwitch=suspend 修改成 HandleLidSwitch=ignore 重启服务 ...
- 图解Numpy的tile函数
Numpy的tile(A, reps)函数,就是将原矩阵横向.纵向地复制.tile是瓷砖的意思,顾名思义,这个函数就是把数组像瓷砖一样铺展开来. 举个例子,原矩阵: 横向铺展: 纵向铺展: 横向铺 ...
- IO流与装饰者模式
java使用IO流来处理不同设备之间数据的交互;所有的IO操作实际上都是对 Stream 的操作 从功能上划分: 输入流: 当数据从源进入的编写的程序时,称它为输入流; 输出流: 从程序输出回另一个源 ...
- Java学习 1.4——第一个Java程序:Hello World!
这一篇一起来写第一个Java程序,同时也了解一下IDEA的使用: 打开IDEA,新建项目: 选择Java,右边project SDK是选择Java版本,上一篇我们自己安装了JDK1.8,IDEA自带一 ...
- 上传图片到七牛云(客户端 js sdk)
大体思路 上一篇我们讲了如何通过服务器生成一个upToken,那前端拿到这个token后又该如何操作?在这里我给出一个相当简洁的版本. 首先我们来看一下上传的思路:调用七牛模块的upload方法,生成 ...
- Java开发人员必备十大工具
Java世界中存在着很多工具,从著名的IDE(例如Eclipse,NetBeans和IntelliJ IDEA)到JVM profiling和监视工具(例如JConsole,VisualVM,Ecli ...
- 在标准实体特殊消息上注册插件及Dynamics CRM 2015中计算字段的使用
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复157或者20151005可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 前面的 插件系列博客教程 讲述了 ...
- JS For
JS For 循环可以将代码块执行指定的次数. JavaScript 循环 document.write(cars[0] + "<br>"); document.wri ...