fix: 解决异步获取默认语言问题

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2024-08-22 13:38:56 +08:00 committed by Craftsman
parent 9c421609fb
commit e4b1d092a9
1 changed files with 8 additions and 8 deletions

View File

@ -17,24 +17,24 @@ const messages = LANG_FILES.keys().reduce((messages, path) => {
return messages; return messages;
}, {}); }, {});
export const getLanguage = () => { export const getLanguage = async () => {
let language = localStorage.getItem('language'); let language = localStorage.getItem('language');
if (!language) { if (!language) {
// 远程接口获取用户语言
language = navigator.language || navigator.browserLanguage; language = navigator.language || navigator.browserLanguage;
axios.get('/system/default-locale').then((response) => { try {
const response = await axios.get('/system/default-locale');
if (response.data && response.data.data) { if (response.data && response.data.data) {
language = response.data.data.replace('_', '-'); language = response.data.data.replace('_', '-');
} }
return language; } catch (error) {
}); language = 'zh-CN';
} else { }
return language;
} }
return language;
}; };
const i18n = new VueI18n({ const i18n = new VueI18n({
locale: getLanguage(), locale: await getLanguage(),
messages, messages,
}); });