vue i18n国际化配置时如何先调用接口再走配置?

vue i18n国际化配置时如何先调用接口再走配置?

import Vue from 'vue';

import VueI18n from 'vue-i18n';

import store from "@/store";

Vue.use(VueI18n);

let langObj = {

LangEn: {},

LangZh: {}

}

if (!JSON.parse(localStorage.getItem("langObj"))) {

store.dispatch("GetLangList").then(res => {

langObj = res

});

} else {

langObj = JSON.parse(localStorage.getItem("langObj"));

}

const messages = {

'en-US': {

...langObj.LangEn

},

'zh-CN': {

...langObj.LangZh

}

}

const i18n = new VueI18n({

locale: localStorage.getItem("lang") || 'en-US',

messages,

});

现在总是先执行下面,第二遍刷新才走上面,如何先调用接口?


回答:

https://kazupon.github.io/vue...

参考延迟加载翻译章节

loadLanguageAsync 方法的动态import改成你的dispatch接口请求

以上是 vue i18n国际化配置时如何先调用接口再走配置? 的全部内容, 来源链接: utcz.com/p/936590.html

回到顶部