【问题标题】:Cannot read properties of undefined (reading 'use') when using Vue.use(VueI18n)使用 Vue.use(VueI18n) 时无法读取未定义的属性(读取“使用”)
【发布时间】:2022-01-11 08:32:41
【问题描述】:

我正在尝试在我的 Vue 项目中制作 i18n, 那么就会发生错误。

Uncaught TypeError: Cannot read properties of undefined (reading 'use')

这是我的项目树:

| -- Project
     | -- src
          | -- App.vue
          | -- main.js
          | -- store
               |-- index.js
          | -- lang
               | -- i18n.js
               | -- tw.json
               | -- en.json

i18n.js:

import Vue from 'vue';
import VueI18n from 'vue-i18n';

Vue.use(VueI18n);

import tw from './tw.json';
import en from './en.json';

const i18n = new VueI18n({
    locale: localStorage.getItem('lang') || 'tw',
    messages: { tw, en }
});

export default i18n;

main.js:

...
import i18n from "./lang/i18n";
app.use(i18n);

"vue": "^3.0.0", “vue-i18n”:“^8.26.8”, 节点:v14.18.0

【问题讨论】:

  • 控制台报错是针对哪个文件main.js或者i18njs

标签: javascript node.js vue.js vue-i18n


【解决方案1】:

添加主js:

new Vue({
  render: h => h(App),
  i18n
}).$mount('#app');

import i18n from "./lang/i18n";

改成

and * as i18n from "./lang/i18n";

【讨论】:

    猜你喜欢
    • 2021-03-27
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 2022-01-27
    • 2020-05-03
    • 1970-01-01
    相关资源
    最近更新 更多