zoukankan      html  css  js  c++  java
  • (已解决)TypeError: Cannot read property '_t' of undefined

    使用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不用更改,更改后会报错。

    我的问题是这样解除的,希望能帮到大家!

    为什么我也不理解,希望大神能够指点,多谢!

  • 相关阅读:
    UI自动化测试框架
    Pyse( selenium-api的二次封装)
    Selenium之webdriverAPI
    selenium 基础之定位方式
    html综合应用
    html基础之js操作
    html基础之Dom操作
    (九)Locust 参数化
    (八)Locust 设置断言
    (七)Locust 的类和方法
  • 原文地址:https://www.cnblogs.com/SamNicole1809/p/11951454.html
Copyright © 2011-2022 走看看