-
Notifications
You must be signed in to change notification settings - Fork 313
Expand file tree
/
Copy pathApp.vue
More file actions
66 lines (58 loc) · 1.58 KB
/
App.vue
File metadata and controls
66 lines (58 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<template>
<td-doc-layout direction="column">
<td-header framework="site" :style="headerStyle" />
<router-view />
</td-doc-layout>
</template>
<script setup>
import { computed, onMounted, onBeforeUnmount, watch } from 'vue';
import { useRoute } from 'vue-router';
const route = useRoute();
// Computed
const headerStyle = computed(() => {
const { name } = route;
const fixedHeaderList = ['home', 'home-en', 'source', 'source-en', 'trade', 'icons', 'icons-en'];
if (fixedHeaderList.includes(name)) {
return {
position: 'fixed',
top: 0,
left: 0,
width: '100%',
zIndex: 1200,
'--bg-color-secondarypage': 'var(--bg-color-navigation)',
'--bg-color-secondarypage-hover': 'var(--bg-color-navigation-hover)',
'--bg-color-secondarypage-select': 'var(--bg-color-navigation-select)',
};
}
return { display: 'none' };
});
// Methods
const handleHashScroll = () => {
const hash = decodeURIComponent(route.hash);
requestAnimationFrame(() => {
const id = hash.slice(1);
const anchorEl = document.getElementById(id);
if (!anchorEl) return;
requestAnimationFrame(() => {
window.scrollTo({ top: anchorEl.offsetTop - 88 });
});
});
};
// Lifecycle hooks
onMounted(() => {
window.addEventListener('load', handleHashScroll);
});
onBeforeUnmount(() => {
window.removeEventListener('load', handleHashScroll);
});
// Watch
watch(
() => route,
(newRoute) => {
if (newRoute && newRoute.meta) {
document.title = newRoute.meta.documentTitle || 'TDesign';
}
},
{ immediate: true, deep: true },
);
</script>