File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
src/.vuepress/theme/components Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 20
20
<template v-for =" (nav , index ) in items " >
21
21
<span
22
22
:key =" `nav-heading-${index}`"
23
- class =" mt-12 ml-4 text-xl font-bold sidebar__title-list bg-primary"
23
+ class =" mt-12 ml-4 text-xl font-bold bg-primary"
24
+ :class =" { 'sidebar__title-list--active': sidebarTitleActive === nav.title }"
24
25
>
25
26
{{ nav.title }}
26
27
</span >
88
89
</template >
89
90
90
91
<script >
91
- import { computed } from ' @vue/composition-api'
92
+ import { computed , ref , watch } from ' @vue/composition-api'
92
93
93
94
import { resolveSidebarItems } from ' @/theme/utils/sidebar'
94
95
@@ -97,8 +98,18 @@ export default {
97
98
98
99
setup (_ , { root }) {
99
100
const items = computed (() => resolveSidebarItems (root .$page .regularPath , root .$site , root .$themeLocaleConfig ))
101
+ const sidebarTitleActive = ref (null )
102
+
103
+ watch (() => root .$route .path , val => {
104
+ const item = items .value .find (item => item .children .some (child => child .path === val))
105
+ if (item) {
106
+ sidebarTitleActive .value = item .title
107
+ }
108
+ }, { immediate: true })
109
+
100
110
return {
101
- items
111
+ items,
112
+ sidebarTitleActive
102
113
}
103
114
}
104
115
}
You can’t perform that action at this time.
0 commit comments