fix: 解决异步获取默认语言问题
Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
parent
9c421609fb
commit
e4b1d092a9
|
@ -17,24 +17,24 @@ const messages = LANG_FILES.keys().reduce((messages, path) => {
|
|||
return messages;
|
||||
}, {});
|
||||
|
||||
export const getLanguage = () => {
|
||||
export const getLanguage = async () => {
|
||||
let language = localStorage.getItem('language');
|
||||
if (!language) {
|
||||
// 远程接口获取用户语言
|
||||
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) {
|
||||
language = response.data.data.replace('_', '-');
|
||||
}
|
||||
return language;
|
||||
});
|
||||
} else {
|
||||
return language;
|
||||
} catch (error) {
|
||||
language = 'zh-CN';
|
||||
}
|
||||
}
|
||||
return language;
|
||||
};
|
||||
|
||||
const i18n = new VueI18n({
|
||||
locale: getLanguage(),
|
||||
locale: await getLanguage(),
|
||||
messages,
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue