【问题标题】:How make vue-i18n works with vue 3?vue-i18n 如何与 vue 3 配合使用?
【发布时间】:2021-04-16 19:27:54
【问题描述】:

我只是用 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"
}

【问题讨论】:

    标签: vue.js vue-i18n


    【解决方案1】:

    您应该使用以下命令安装最新版本:

    npm uninstall vue-i18n
    

    然后

    npm i vue-i18n@next
    

    因为vue-i18n@9.x 兼容vue 3

    【讨论】:

      猜你喜欢
      • 2021-10-20
      • 1970-01-01
      • 2023-03-13
      • 2023-04-02
      • 2019-04-19
      • 2019-09-21
      • 2021-09-05
      • 2021-04-01
      相关资源
      最近更新 更多