第一种方法
首先要确保在main.js里面把vue挂在在window.vm下(vm这个名字可以自定义)
window.vm = new Vue({
el: '#app',
i18n,
router,
store,
render: h => h(App)
})
其次,在弹出框中写多语言时需要加上vm.
比如平时在写多语言时是写{{$t('xxxxx')}}
或 this.$t('xxx')
这时就需要写{{vm.$t('xxxxx')}}
或 this.vm.$t('xxxxx')
第二种方法
在引用组件时将this传递进子组件
如:
<model-card
:that = "that"
:dialogVisible.sync="showModelDialog"
@closeDialog="handleCloseDialog"
>
props: {
that: Object, // this指向,用于防止使用Vue.extend时,国际化无法引用
}
使用时:this.that.$t('i18n.iconLibrary')