vue-i18n 如何与 vue 3 一起使用?
How make vue-i18n works with vue 3?
我刚刚用 Vue 3 安装 vue-i18n
我遇到了错误;
我的代码在 app.js
文件中
import { createApp } from 'vue';
// ......
import en from './translate/en.json'
import ar from './translate/ar.json'
import ku from './translate/ku.json'
import { createI18n } from "vue-i18n";
const i18n = createI18n({
locale: 'ar',
messages: {
en,
ar,
ku,
}
})
const el = document.getElementById('app');
const app = createApp(App);
app.use(i18n);
app.mount(el);
错误:
WARNING in ./js/app.js 13:11-21
export 'createI18n' (imported as 'createI18n') was not found in 'vue-i18n' (possible exports: default)
webpack compiled with 1 warning
在控制台中:
Uncaught TypeError: vue_i18n__WEBPACK_IMPORTED_MODULE_7__.createI18n is not a function
package.json
"dependencies": {
"tiny-emitter": "^2.1.0",
"vue-i18n": "^8.24.3"
}
您应该使用以下命令安装最新版本:
npm uninstall vue-i18n
然后
npm i vue-i18n@next
因为vue-i18n@9.x
兼容vue 3
我刚刚用 Vue 3 安装 vue-i18n
我遇到了错误;
我的代码在 app.js
文件中
import { createApp } from 'vue';
// ......
import en from './translate/en.json'
import ar from './translate/ar.json'
import ku from './translate/ku.json'
import { createI18n } from "vue-i18n";
const i18n = createI18n({
locale: 'ar',
messages: {
en,
ar,
ku,
}
})
const el = document.getElementById('app');
const app = createApp(App);
app.use(i18n);
app.mount(el);
错误:
WARNING in ./js/app.js 13:11-21
export 'createI18n' (imported as 'createI18n') was not found in 'vue-i18n' (possible exports: default)
webpack compiled with 1 warning
在控制台中:
Uncaught TypeError: vue_i18n__WEBPACK_IMPORTED_MODULE_7__.createI18n is not a function
package.json
"dependencies": {
"tiny-emitter": "^2.1.0",
"vue-i18n": "^8.24.3"
}
您应该使用以下命令安装最新版本:
npm uninstall vue-i18n
然后
npm i vue-i18n@next
因为vue-i18n@9.x
兼容vue 3