Vue-element-admin: $t not function but .vue file ok

Created on 1 Jun 2018  ·  5Comments  ·  Source: PanJiaChen/vue-element-admin

Hi @PanJiaChen
Sorry to contact you here, couldn’t find you elsewhere.
I read your article on vue-element-admin, and really like it.

我在.vue文件里面能正常使用国际化$t function 但是在工具类util文件里面单个js文件就不能使用,我不知道是为什么原因。比如:

MessageBox.confirm('Token已经过期,你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', {
        confirmButtonText: '重新登录',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

改成

MessageBox.confirm(this.$t('message.xxxxxxx'), {
        confirmButtonText: '重新登录',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

console error
$t is not function

question

Most helpful comment

import i18n from '@/lang' 
....

 MessageBox.confirm(i18n.t('login.title'), {
    confirmButtonText: '重新登录',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {})

https://github.com/kazupon/vue-i18n/issues/184

All 5 comments

 const vm = this
 MessageBox.confirm(vm.$t('message.xxxxxxx'), {
   confirmButtonText: '重新登录',
   cancelButtonText: '取消',
   type: 'warning'
 }).then(() => {})

@PanJiaChen

vm.$t is not a function

还是不行啊,大佬。你自己试了没有啊

import i18n from '@/lang' 
....

 MessageBox.confirm(i18n.t('login.title'), {
    confirmButtonText: '重新登录',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {})

https://github.com/kazupon/vue-i18n/issues/184

非常感谢花裤衩大佬,好人一生平安,发大财。

Was this page helpful?
0 / 5 - 0 ratings