簡體   English   中英

通過axios調用設置vue-router消息

[英]Set vue-router messages via axios call

我想通過對后端應用程序的api調用獲取翻譯消息。 axios調用的then回調中,我想設置消息。

但是問題似乎是VueRouter已經用空翻譯初始化,並且沒有從then回調中重新加載新的翻譯。

我有辦法實現這一目標嗎?

我試過了:

let messages = {};
window.axios.get(route('api.translation.translations.all'))
    .then(response => {
        messages = {
            [currentLocale]: response.data,
        }
    });
console.log(messages);

const i18n = new VueI18n({
    locale: currentLocale, 
    messages, 
});

由於無法在完全設置消息之前調用new VueI18n因此無法使用。

window.axios.get(route('api.translation.translations.all'))
    .then(response => {
        messages = {
            [currentLocale]: response.data,
        };
        console.log(messages);
        app.$i18n.setLocaleMessage('en', messages)
    });

這也不起作用。

謝謝!

找到解決方案后,我不需要指定語言環境,因為它是setLocaleMessage的第一個參數。

window.axios.get(route('api.translation.translations.all'))
    .then(response => {
        messages = response.data;

        app.$i18n.setLocaleMessage(currentLocale, messages);
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM