-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(projects): move changing document title by locale to global even…
…t of composables & add appLoading unmount
- Loading branch information
1 parent
5f6caab
commit 08e194e
Showing
3 changed files
with
22 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ async function setupApp() { | |
|
||
setupI18n(app); | ||
|
||
appLoading.unmount(); | ||
|
||
// mount app | ||
app.mount('#app'); | ||
} | ||
|