diff --git a/src/components/PageToc.vue b/src/components/PageToc.vue new file mode 100644 index 00000000..b57229ac --- /dev/null +++ b/src/components/PageToc.vue @@ -0,0 +1,59 @@ + + + + + diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 4affe906..3c620067 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -14,8 +14,8 @@ v-for="(item, index) in $store.getters.sidebar" :key="index" :item="item" - :open="currentOpenIndex === index" - @toggle="openSidebar(index)" + :open="openItems.indexOf(index) !== -1" + @toggle="toggleItem(index)" /> @@ -35,23 +35,33 @@ export default { }, data() { return { - currentOpenIndex: 0 + openItems: [] } }, watch: { '$route.path': { handler() { - this.currentOpenIndex = this.getCurrentIndex( + const index = this.getCurrentIndex( this.$route.path, this.$store.getters.sidebar ) + this.openItem(index) }, immediate: true } }, methods: { - openSidebar(index) { - this.currentOpenIndex = this.currentOpenIndex === index ? -1 : index + openItem(index) { + if (this.openItems.indexOf(index) === -1) { + this.openItems.push(index) + } + }, + toggleItem(index) { + if (this.openItems.indexOf(index) === -1) { + this.openItems.push(index) + } else { + this.openItems = this.openItems.filter(v => v !== index) + } }, getCurrentIndex(currentPath, sidebarItems) { for (let idx = 0; idx < sidebarItems.length; idx++) { @@ -63,7 +73,7 @@ export default { return idx } } - return -1 + return 0 }, getChildren(item) { return item.children || item.links || [] diff --git a/src/components/SidebarItem.vue b/src/components/SidebarItem.vue index df7a3aec..8a2f4055 100644 --- a/src/components/SidebarItem.vue +++ b/src/components/SidebarItem.vue @@ -2,60 +2,66 @@
- {{ item.title }} - + + + + + + {{ item.title }} +
+ {{ item.title }} +
+
- + +
+