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 2020 <template v-for =" (nav , index ) in items " >
2121 <span
2222 :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 }"
2425 >
2526 {{ nav.title }}
2627 </span >
8889</template >
8990
9091<script >
91- import { computed } from ' @vue/composition-api'
92+ import { computed , ref , watch } from ' @vue/composition-api'
9293
9394import { resolveSidebarItems } from ' @/theme/utils/sidebar'
9495
@@ -97,8 +98,18 @@ export default {
9798
9899 setup (_ , { root }) {
99100 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+
100110 return {
101- items
111+ items,
112+ sidebarTitleActive
102113 }
103114 }
104115}
You can’t perform that action at this time.
0 commit comments