正常使用
importVueI18n from'vue-i18n'Vue.use(VueI18n)importi18nZH from'@/assets/common/lang/zh'importi18nEN from'@/assets/common/lang/en'//i18nconsti18n=newVueI18n({locale:'zh-CN',messages:{'zh-CN':i18nZH,'en-US':i18nEN}})newVue({router,store,i18n,render:h=>h(App)}).$mount('#app')//使用<div>$t('somethings')</div>
把实例i18n挂载到Vue实例上就可以(实例变量i18n不可更改,更改回报_t undefined的错误)
***但是由于项目问题,没有new Vue()实例,所以把i18n挂到Vue原型
在main.js中挂在原型连
Vue.prototype.$i18nn = i18n
<div>$i18nn.t('somethings')</div>