浏览代码

fix: 修复国际化切换到英文模式刷新会回到中文模式

xiaoxian521 1 年之前
父节点
当前提交
315f78a825
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      src/layout/hooks/useTranslationLang.ts

+ 5 - 1
src/layout/hooks/useTranslationLang.ts

@@ -1,7 +1,7 @@
 import { useNav } from "./useNav";
 import { useI18n } from "vue-i18n";
 import { useRoute } from "vue-router";
-import { watch, type Ref } from "vue";
+import { watch, onBeforeMount, type Ref } from "vue";
 
 export function useTranslationLang(ref?: Ref) {
   const { $storage, changeTitle, handleResize } = useNav();
@@ -27,6 +27,10 @@ export function useTranslationLang(ref?: Ref) {
     }
   );
 
+  onBeforeMount(() => {
+    locale.value = $storage.locale?.locale ?? "zh";
+  });
+
   return {
     t,
     route,