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,
});

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

阅读 2.9k
1 个回答
推荐问题