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 ...
随机推荐
- 数据库(一)--通过django创建数据库表并填充数据
django是不能创建数据库的,只能够创建数据库表,因此,我们在连接数据库的时候要先建立一个数据库. 在models.py中 from django.db import models class Pu ...
- 【Java必修课】通过Value获取Map中的键值Key的四种方法
1 简介 我们都知道Map是存放键值对<Key,Value>的容器,知道了Key值,使用方法Map.get(key)能快速获取Value值.然而,有的时候我们需要反过来获取,知道Value ...
- 关于typedef和struct
在struct中使用自身,需要加struct关键字,无论带不带typedef,例如: struct A { int a; struct A *pA; }; 在定义struct方面尽量不要使用typed ...
- js如何展示上传的图片
前言:本文章主要讲的是上传的图片如何展示在页面上. 一般来说,我们会先将本地图片上传到服务器,上传成功后,由后台返回图片的网络地址再在前端显示.但是,我今天讲的是不通过前面说的过程,而是直接使用js将 ...
- API 网关知识看这篇就足够了!
本文已经收录自 JavaGuide (60k+ Star[Java学习+面试指南] 一份涵盖大部分Java程序员所需要掌握的核心知识.) 本文授权转载自:https://github.com/java ...
- 好看的原生UI
我前端可以说是0基础,作显示页面的时候自己设置各种CSS一是麻烦,二是难看,所以找UI组件, 比较流行的组件如ELEMENT之类都需要安装或者依赖其他框架如VUE,为了省事,决定使用原生UI组件, 本 ...
- 学习笔记24_MVC前后台数据交互
*最普通的交互方式,在Contoller中的Action方法内 public ActionResult Index() { ViewData["Key"] =Value; Retu ...
- Linux下修改文件权限,所有权
Linux与Unix是多用户操作系统,所以文件的权限与所有权的实现就显得很有必要:每个文件主要与三组权限打交道,分别是用户(user),用户组(group),其他用户(other) 用户(u)是文件的 ...
- 敏捷宣言(Agile Manifesto)和敏捷开发十二原则
敏捷宣言 The Agile Manifesto Individuals and interactions over Process and tools 个体与交互 重于 过程和工具 Working ...
- nginx篇最初级用法之访问认证
1打开conf下的配置文件 在server 之下 location 之上加入 auth_basic "Input Password:"; 弹出的提示信息 auth_basic ...