fix: 挂载前根据默认语言在设置一次

This commit is contained in:
TsMask
2023-12-04 18:17:28 +08:00
parent a1443ebb95
commit 205e07af45

View File

@@ -1,6 +1,6 @@
import { computed } from 'vue';
import { computed, onBeforeMount } from 'vue';
import { useI18n } from 'vue-i18n';
import { localSet } from '@/utils/cache-local-utils';
import { localGet, localSet } from '@/utils/cache-local-utils';
import { CACHE_LOCAL_I18N } from '@/constants/cache-keys-constants';
export default function useLocale() {
@@ -31,6 +31,14 @@ export default function useLocale() {
},
];
// 挂载前根据默认语言在设置一次
onBeforeMount(() => {
const localI18n = localGet(CACHE_LOCAL_I18N);
if (localI18n) {
i18n.locale.value = localI18n;
}
});
return {
optionsLocale,
currentLocale,