TypeError: Cannot read property '_t' of undefined (VUE + ElementUI + i18n)
使用vue的ElementUI库,在多语言时报错:
TypeError: Cannot read property '_t' of undefined
错误是在点菜单栏时随机抛出的,F12抓不到,只是报错提示。
vue => 2.6.10
element-ui => 2.7.2
vue-i18n => 8.15.0
配置和文件路径如下(index.js):
import Vue from 'vue'
import VueI18n from 'vue-i18n' Vue.use(VueI18n) import zh from './config/zh'
import en from './config/en' const i18n = new VueI18n({
locale: localStorage.getItem('locale') || 'zh',
messages: {
zh,
en
}
}) export default i18n

页面翻译功能正常。
经过多次尝试,问题出现的原因是:
在js中使用了如下代码进行翻译:
this.$t('...')
解决办法:
引入index.js中的i18n,在页面中采用i18n.t替换this.$t('...')
// 引入i18n
import i18n from '@/i18n/index' // js中使用如下代替this.$t
i18n.t('...')
需要说明的是,在template中的this.$t不用更改,更改后会报错。
我的问题是这样解除的,希望能帮到大家!
为什么我也不理解,希望大神能够指点,多谢!
TypeError: Cannot read property '_t' of undefined (VUE + ElementUI + i18n)的更多相关文章
- vue 报错解决:TypeError: Cannot read property '_t' of undefined"
前端报错如下: [Vue warn]: Error in render: "TypeError: Cannot read property '_t' of undefined" 是 ...
- 转载:TypeError: Cannot read property 'compilation' of undefined vue 打包运行npm run build 报错
转载自:https://www.jianshu.com/p/3f8f60e01797 运行npm run build打包时,报错如下: 我的package.json如下: { ... " ...
- vue.common.js?e881:433 TypeError: Cannot read property 'nodeName' of undefined
我觉得吧,是这么个原因,就是响应式要找这个node改它的内容,没找着,就报错了. 用computed监控vuex的state属性,绑定到页面上,如果这个属性改了,因为响应式,那么就要更改页面,如果页面 ...
- vue v-if:"TypeError: Cannot read property 'length' of undefined"
在使用v-if判断一个数组大小为0时,会出现 length 是undefined的错误:[Vue warn]: Error in render: "TypeError: Cannot rea ...
- vue项目使用echarts按需引入实现地图动态显示效果时,报错:TypeError: Cannot read property 'dataToPoint' of undefined
vue项目使用echarts按需引入实现地图动态显示效果时,报错:TypeError: Cannot read property 'dataToPoint' of undefined 借鉴了该大神的文 ...
- VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法
正常情况下在data里面都有做了定义 在函数里面进行赋值 这时候你运行时会发现,数据可以请求到,但是会报错 TypeError: Cannot set property 'listgroup' of ...
- vue表单校验提交报错TypeError: Cannot read property 'validate' of undefined
TypeError: Cannot read property 'validate' of undefined at VueComponent.submitForm (plat_users.html: ...
- Vue使用Typescript开发编译时提示“ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'afterCompile' of undefined”的解决方法
使用Typescript开发Vue,一切准备就绪.但npm start 时,提示“ ERROR in ./src/main.tsModule build failed: TypeError: Cann ...
- [Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined、vuejs路由使用的问题Error in render function
1.[Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined 注意,只要出现Error i ...
随机推荐
- 你的 Java 并发程序 Bug,100% 是这几个原因造成的
可见性问题 可见性是指一个线程对共享变量进行了修改,其他线程能够立马看到该共享变量更新后的值,这视乎是一个合情合理的要求,但是在多线程的情况下,可能就要让你失望了,由于每个 CPU 都有自己的缓存,每 ...
- TwoHandleSlider/RangeSlider
项目需求:双滑块slider,可以实现选择一个范围 (一)添加两个slider,并把背景以及fill设置为透明,并去除RaycastTarget (二)在背景下添加个一个image,背景图为滑块划过后 ...
- django-ForeignKey,OneToOneField,ManyToManyField
进入到django自带的related.py中,可以看到 1.ForeignKey 初始化的参数有: to, on_delete, related_name=None, related_query_n ...
- laravel6.0控制器-资源控制器
控制器:控制器用来处理业务的,不应该处理逻辑,如果是小项目可以把逻辑写到控制器里,大点的项目应该抽离出来业务处理层如下:services业务处理层:比如:获取值,验证值,异常捕获命名规则:控制器名:用 ...
- MySQL学习之路(1):SQL脚本语言
使用MySQL数据库,首先安装MySQL数据库,本文所有SQL脚本在MySQL上测试和执行. 安装Mysql服务器:安装Mysql workbench客户端,可以以图形化界面管理mysql:安装php ...
- PHP函数preg_match()
部分内容来自:http://www.nowamagic.net/librarys/veda/detail/1054 preg_match — 进行正则表达式匹配. 语法:int preg_match ...
- 几种部署Goku API Gateway的方式,最快一分钟可使用上网关
本文将介绍几种部署Goku API Gateway的方式,最快一分钟可使用上为网关,详情请看全文. 什么是Goku API Gateway? Goku API Gateway (中文名:悟空 API ...
- 学习笔记14Js使用技巧
**页面加载完毕时执行一段代码$(fuction(){ initialMethod(); }); *将一个<form>序列化为json对象并传给服务器var postData = $(&q ...
- 学习笔记62_python文件操作
#使用 str = raw_input("输入密码:") 来获取键盘的输入 #创建或打开一个文件 fp = open("hellow.txt","w& ...
- word转HTML部署到服务器不能运行
已经解决.在网上找的:网址:http://blog.sina.com.cn/s/blog_852ca01901016lyz.html远程调用Excel.Word.PowerPoint,服务器端设置(2 ...