如题。
会报【TypeError: Cannot read property '_t' of undefined】
vue组件中做成nvue的引入方式也是不可以。
这种情况有什么解决方案?

如题。
会报【TypeError: Cannot read property '_t' of undefined】
vue组件中做成nvue的引入方式也是不可以。
这种情况有什么解决方案?
苏公子 (作者)
找到了解决方案:在引入的vue组件中使用条件编译引入i18n插件即可。
// 页面引入mixin
import locale from '@/mixin/locale.js'
mixins: [locale]
// mixin内容
import { initVueI18n } from '@dcloudio/uni-i18n'
import messages from '@/locale/index.js'
const i18n = initVueI18n(messages)
export default {
data() {
return {
}
},
methods: {
$t(key, obj) {
return i18n.t(key, obj)
},
}
}