From 205e07af4537fbc73d4f91f48118efa365ae0ee6 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 4 Dec 2023 18:17:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8C=82=E8=BD=BD=E5=89=8D=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E9=BB=98=E8=AE=A4=E8=AF=AD=E8=A8=80=E5=9C=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useI18n.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/hooks/useI18n.ts b/src/hooks/useI18n.ts index f362781e..e9bed48a 100644 --- a/src/hooks/useI18n.ts +++ b/src/hooks/useI18n.ts @@ -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() { @@ -20,7 +20,7 @@ export default function useLocale() { }; // 可选的语言 - const optionsLocale= [ + const optionsLocale = [ { value: 'zh_CN', label: '中文', @@ -31,6 +31,14 @@ export default function useLocale() { }, ]; + // 挂载前根据默认语言在设置一次 + onBeforeMount(() => { + const localI18n = localGet(CACHE_LOCAL_I18N); + if (localI18n) { + i18n.locale.value = localI18n; + } + }); + return { optionsLocale, currentLocale,