How to solve the problem of vue-i18n internationalization probability error: Cannot read property'_ t'of null?

using internationalized plug-ins in vue projects will cause probabilistic errors when switching pages.: Uncaught TypeError: Cannot read property"_ t"of null at VueComponent.Vue.$t, keeps repeating errors in an orderly manner (for example, 4 errors at a time). If I refresh the page, the error will stop.

clipboard.png

Dec.02,2021

vue project, when the route jumps quickly, vue-18n has a certain probability of reporting an error Cannot read property'_ t'of null.

reason (my own understanding):
page An and page B are configured in multiple languages, such as
$t ('xxx') in html, this.$t (' xxx') in data or method.
when page A jumps to page B, the multilingual loading of page An is not finished but has already jumped to page B, so the this in page A cannot be found.

solution:
multilingual configuration file (my project is i18n/index.js under src)

import Vue from 'vue'
import VueI18n from 'vue-i18n'

import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import enLocale from 'element-ui/lib/locale/lang/en'
import jaLocale from 'element-ui/lib/locale/lang/ja'

Vue.use(VueI18n) // 

let messages = {
  'zh-CN': { ...require('./zh'), ...zhLocale },
  'en-US': { ...require('./en'), ...enLocale },
  'ja-JP': { ...require('./ja'), ...jaLocale },
}

const i18n = new VueI18n({
  locale: 'zh-CN', // 
  messages
})

export default i18n

change this.$t ('xxx') to i18n.t (' xxx') from i18n
page to i18n.t ('xxx')

when configuring a single page with multiple languages.
import i18n from '@/i18n/index'
Menu