苏公子
苏公子
  • 发布:2025-03-27 11:19
  • 更新:2025-04-09 11:06
  • 阅读:61

#插件讨论# 【 hello-i18n 示例工程 - DCloud前端团队 】nvue报错

分类:uni-app
关联插件: hello-i18n 示例工程

如果页面是nvue,引用的自定义组件或第三方组件是vue,这种情况如何处理?
目前出现的情况是:自定义或第三方组件中的 $t 会报错。

2025-03-27 11:19 负责人:无 分享
已邀请:
苏公子

苏公子 (作者)

找到了解决方案:在引入的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)  
        },  
    }  
}

要回复问题请先登录注册