【问题标题】:What's format of `en.js` or `ja.js` in lazy load vue-i18n延迟加载vue-i18n中`en.js`或`ja.js`的格式是什么
【发布时间】:2019-08-22 19:28:15
【问题描述】:

延迟加载中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',
});

我该怎么办?

【问题讨论】:

    标签: javascript json vue.js vue-i18n


    【解决方案1】:

    您需要包含所有语言文件并将它们分配给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
     }
    });
    

    【讨论】:

    • 谢谢,但我在编译时出错`找不到模块:错误:无法解析 'C:\wamp64\www\front-tutorial-example\laravel\resources\ 中的 'lang/fa'资产\js'`。 en.js 的格式就像我的问题
    猜你喜欢
    • 2022-06-20
    • 2010-09-07
    • 2021-02-12
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    相关资源
    最近更新 更多