|
3 | 3 | :color="drawerOptions.color ? 'white' : 'primary'" |
4 | 4 | density="compact" |
5 | 5 | > |
6 | | - <template v-for="item in menuItems"> |
| 6 | + <template v-for="item, k in menuItems"> |
7 | 7 | <v-list-group |
8 | 8 | v-if="item.items" |
9 | | - :key="item.items" |
| 9 | + :key="k" |
10 | 10 | :value="item.title" |
11 | 11 | > |
12 | 12 | <template v-slot:activator="{ props }"> |
|
51 | 51 | </v-list> |
52 | 52 | </template> |
53 | 53 |
|
54 | | -<script setup> |
55 | | -import { inject, onMounted, ref } from 'vue'; |
| 54 | +<script setup lang="ts"> |
56 | 55 | import { useMenuStore } from '@/stores/menu'; |
57 | 56 |
|
58 | | -const drawerOptions = inject('drawerOptions'); |
59 | | -const store = useMenuStore(); |
60 | 57 |
|
61 | | -const active = ref(''); |
62 | | -const menuItems = store.menuItems; |
| 58 | +const drawerOptions = inject<Docs.DrawerOptions>('drawerOptions')!; |
| 59 | +const store = useMenuStore(); |
| 60 | +const active = ref<string>(''); |
| 61 | +const menuItems: Docs.MenuItem[] = store.menuItems; |
63 | 62 |
|
64 | 63 | onMounted(() => { |
65 | 64 | smoothScroll(); |
66 | 65 |
|
67 | 66 | active.value = window.location.hash || '#home'; |
68 | 67 | }); |
69 | 68 |
|
70 | | -function smoothScroll() { |
71 | | - document.querySelectorAll('a[href^="#"]').forEach((anchor) => { |
72 | | - anchor.addEventListener('click', (e) => { |
| 69 | +function smoothScroll(): void { |
| 70 | + document.querySelectorAll<HTMLAnchorElement>('a[href^="#"]').forEach((anchor) => { |
| 71 | + anchor.addEventListener('click', (e: MouseEvent) => { |
73 | 72 | e.preventDefault(); |
74 | 73 |
|
75 | | - const hash = anchor.hash; |
76 | | - const id = hash.replace('#', ''); |
77 | | - const yOffset = -55; |
78 | | - const element = document.getElementById(id); |
79 | | - const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset; |
| 74 | + const hash: string = anchor.hash; |
| 75 | + const id: string = hash.replace('#', ''); |
| 76 | + const yOffset: number = -55; |
| 77 | + const element: HTMLElement | null = document.getElementById(id); |
80 | 78 |
|
81 | | - active.value = hash; |
| 79 | + if (element) { |
| 80 | + const y: number = element.getBoundingClientRect().top + window.pageYOffset + yOffset; |
82 | 81 |
|
83 | | - window.location.hash = hash; |
84 | | - window.scrollTo({ behavior: 'smooth', top: y }); |
| 82 | + active.value = hash; |
| 83 | +
|
| 84 | + window.location.hash = hash; |
| 85 | + window.scrollTo({ behavior: 'smooth', top: y }); |
| 86 | + } |
85 | 87 | }); |
86 | 88 | }); |
87 | 89 | } |
88 | | -
|
89 | 90 | </script> |
90 | 91 |
|
91 | 92 | <style lang="scss" scoped> |
|
0 commit comments