javascript - 延迟加载 vue-i18n 中 `en.js` 或 `ja.js` 的格式是什么

标签 javascript json vue.js vue-i18n

延迟加载时en.jsja.js 是什么格式?下面的代码不起作用:

// en.js
export default
    {
        title: 'Title',
        greeting: 'How are you'
    };

import Vue from 'vue';
import InventoryList from "./components/InventoryList";
import VueI18n from 'vue-i18n';
import messages from 'lang/fa';

Vue.use(VueI18n);

const i18n = new VueI18n({
    locale: 'en',
    fallbackLocale: 'en',
    messages
});

Vue.component('inventory-list', InventoryList);

const app = new Vue({
    i18n,
    el: '#app',
});

我该怎么办?

最佳答案

您需要包含所有语言文件并将它们分配给 VueI18n init 调用中的 messages 键。

像这样:

import fa from './lang/fa' // relative path
import en from './lang/en' // relative path
...
const i18n = new VueI18n({
 locale: 'en',
 fallbackLocale: 'en',
 messages: {
  en,
  fa
 }
});

关于javascript - 延迟加载 vue-i18n 中 `en.js` 或 `ja.js` 的格式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55458370/

相关文章:

javascript - 在 element ui Vuejs 的 el-table 中添加/删除列后如何调整列?

vue.js - 在 Vuetify 中调整 v-list-tile 的高度

javascript - 在现有 div 上渲染 div

javascript - 将数组作为键值添加到对象数组中

javascript - 如何 json.stringify() 一个字符串

json - 结合类型和字段序列化器

javascript - Vue使用输入修改图表

javascript - 为什么当我的 javascript 函数返回 false 时我的表单仍然提交?

javascript - CSS 向左滚动

python - 在 Python 中解析 Json(字典中的列表)