1. 开发环境报错Uncaught (in promise) TypeError: ‘set’ on proxy: trap returned falsish for property ‘$t’
legacy需要设置为false
const i18n = createI18n({
legacy: false,
// 默认语言
locale: lang,
// 设置语言环境
messages,
})
2. 打包配置tsc --noEmit时报错:Type instantiation is excessively deep and possibly infinite
messages需要设置类型
import { I18nOptions } from 'vue-i18n';
const messages = {
'zh-CN': { ...zhCN },
'en-US': { ...enUS },
} as I18nOptions['messages'];
3.Uncaught (in promise) TypeError: _ctx.$t is not a function
$t需要全局注册, globalInjection设置为true
const i18n = createI18n({
legacy: false,
// 默认语言
locale: lang,
// 设置语言环境
messages,
globalInjection: true,
})