From 08e194efe9a8b480ed87585fcd712d18ddb88f4e Mon Sep 17 00:00:00 2001 From: Soybean Date: Wed, 31 May 2023 01:44:18 +0800 Subject: [PATCH] perf(projects): move changing document title by locale to global event of composables & add appLoading unmount --- src/App.vue | 12 ------------ src/composables/events.ts | 20 ++++++++++++++++++++ src/main.ts | 2 ++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/App.vue b/src/App.vue index 38294b4c6..a801c8557 100644 --- a/src/App.vue +++ b/src/App.vue @@ -13,26 +13,14 @@ diff --git a/src/composables/events.ts b/src/composables/events.ts index b8c326b4e..c780870a1 100644 --- a/src/composables/events.ts +++ b/src/composables/events.ts @@ -1,14 +1,34 @@ +import { effectScope, onScopeDispose, watch } from 'vue'; +import { useRoute } from 'vue-router'; import { useEventListener } from '@vueuse/core'; +import { useI18n } from 'vue-i18n'; import { useTabStore, useThemeStore } from '@/store'; /** 全局事件 */ export function useGlobalEvents() { const theme = useThemeStore(); const tab = useTabStore(); + const route = useRoute(); + const { locale, t } = useI18n(); + const scope = effectScope(); /** 页面离开时缓存多页签数据 */ useEventListener(window, 'beforeunload', () => { theme.cacheThemeSettings(); tab.cacheTabRoutes(); }); + + scope.run(() => { + // 国际化切换时更新浏览器标签文本 + watch( + () => locale.value, + () => { + document.title = route.meta.i18nTitle ? t(route.meta.i18nTitle) : route.meta.title; + } + ); + }); + + onScopeDispose(() => { + scope.stop(); + }); } diff --git a/src/main.ts b/src/main.ts index a31616d67..a6e94c09a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,6 +29,8 @@ async function setupApp() { setupI18n(app); + appLoading.unmount(); + // mount app app.mount('#app'); }