Uncaught SyntaxError: Need to install with `app.use` function (at message-compiler.esm-bundler.js:54:19)
at createCompileError (message-compiler.esm-bundler.js:54:19)
at createI18nError (vue-i18n.esm-bundler.js:100:12)
at useI18n (vue-i18n.esm-bundler.js:2219:15)
at setup (App.vue:29:18)
at callWithErrorHandling (runtime-core.esm-bundler.js:155:22)
at setupStatefulComponent (runtime-core.esm-bundler.js:7204:29)
at setupComponent (runtime-core.esm-bundler.js:7159:11)
at mountComponent (runtime-core.esm-bundler.js:5508:13)
at processComponent (runtime-core.esm-bundler.js:5483:17)
at patch (runtime-core.esm-bundler.js:5085:21)
意思說createI18n 未創建,就使用了useI18n 方法,造成報錯。
看到這個大哥vue3+i18n 國際化處理,後面才知道原來寫的順序錯了,因爲我先做了
app.mount('#app')
在做了
app.use(i18n)
只需要修改成
app.use(i18n)
app.mount('#app')
後續又報錯Not available in legacy mode
只需要在createI18n的方法裏面加上legacy: false,
即