提交 | 用户 | 时间
|
314507
|
1 |
import { watch, ref } from 'vue' |
H |
2 |
import { isString } from '@/utils/is' |
|
3 |
import { useAppStoreWithOut } from '@/store/modules/app' |
|
4 |
|
|
5 |
const appStore = useAppStoreWithOut() |
|
6 |
|
|
7 |
export const useTitle = (newTitle?: string) => { |
|
8 |
const { t } = useI18n() |
|
9 |
const title = ref( |
|
10 |
newTitle ? `${appStore.getTitle} - ${t(newTitle as string)}` : appStore.getTitle |
|
11 |
) |
|
12 |
|
|
13 |
watch( |
|
14 |
title, |
|
15 |
(n, o) => { |
|
16 |
if (isString(n) && n !== o && document) { |
|
17 |
document.title = n |
|
18 |
} |
|
19 |
}, |
|
20 |
{ immediate: true } |
|
21 |
) |
|
22 |
|
|
23 |
return title |
|
24 |
} |