最近用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>'的更多相关文章

  1. 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>' ...

  2. 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 ...

  3. Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

    Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>' 点开错误的文 ...

  4. Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决方法

    发现问题 运行一下以前的一个Vue+webpack的 vue仿新闻网站  小项目,报错 由于自己vue学习不深入,老是这个报错,找了好久(确切的说是整整一下午^...^)才找到原因 -v- Uncau ...

  5. 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 ...

  6. vue 项目的I18n国际化之路

    I18n (internationalization ) ---未完善 产品国际化是产品后期维护及推广中重要的一环,通过国际化操作使得产品能更好适应不同语言和地区的需求 国际化重点:1. 语言语言本地 ...

  7. spring中使用i18n(国际化)

    简单了解i18n i18n(其来源是英文单词internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称.在资讯领域,国际化(i18n)指让产品(出版物,软件,硬件 ...

  8. javascript 及 vue 中的变量前面的美元符号 $ 是什么意思

    $ 您会注意到,我们将库代理为以美元符号“$”为前缀的属性名. 你可能还看过其他的属性和方法,例如,$refs, $on, $mount等等也都是以”$”开头. 虽然属性名上添加前缀不是必须的,但是这 ...

  9. 项目中遇到Uncaught TypeError: Converting circular structure to JSON报错问题

    最近公司项目中出现一个报错Uncaught TypeError: Converting circular structure to JSON,,根据上述报错可以知道代码是运行到JSON.stringi ...

随机推荐

  1. 深入理解 Java 异常

  2. ASP.NET Core 3.0 使用 gRPC无法编译问题

    一.问题 创建了gRPC项目后,编译发现报错: 二.解决 1.检查项目路径是否存在中文 2.检查当前Windows用户目录是否为非英文字符,如果是则必须改为英文 修改方法: https://jingy ...

  3. ZooKeeper(三):请求处理链路的创建过程解析

    我们知道,zk就是一个个处理链组成的. 但是,这些处理链是在什么创建的呢? ZooKeeper 中有三种角色的服务节点存在: Leader, Follower, Observer . 而每个服务节点的 ...

  4. Change Field Layout and Visibility in a List View 在列表视图中更改字段布局和可见性

    This lesson will guide you through the steps needed to select columns displayed in the List View. Fo ...

  5. Vue中调用另一个组件中自定义事件

    之前在一个场景中,遇到组件需要调用父组件中的方法tableInit(),字组件调用父组件常用的有三种方法,具体参考:https://www.cnblogs.com/jin-zhe/p/9523782. ...

  6. PHP fnmatch 文件系统函数

    定义和用法 fnmatch - 用模式匹配文件名 目前该函数无法在 Windows 或其它非 POSIX 兼容的系统上使用. 版本支持 PHP4 PHP5 PHP7 4.3.0(含)+支持 支持 支持 ...

  7. JavaScript 语句解析

    在 HTML 中,JavaScript 语句是由 web 浏览器“执行”的“指令”. 实例 var x, y, z; // 语句 1 x = 22; // 语句 2 y = 11; // 语句 3 z ...

  8. Linux Shell之监测磁盘空间

    Linux Shell之监测磁盘空间 系统管理员的另一个重要任务就是监测系统磁盘的使用情况.不管运行的是简单Linux台式机还是大型的Linux服务器,我们都要知道还有多少空间可以留给应用程序.事实上 ...

  9. mysql忧化参数

    转自 https://blog.51cto.com/tongcheng/1710265以下参数是在mysql-5.6.27中使用,可能mysql版本不同使用方法不一样1.线程参数innodb_read ...

  10. Octave中的一些常用操作

    >> 5+6ans = 11>> 1~=2ans = 1 %1表示true,0表示false>> 1~=1    %1不等于1ans = 0>> a=2 ...