Skip to content

Commit 390563d

Browse files
authored
fix: by monitoring the route, display the corresponding directory content in the left menu (#2278)
* fix: by monitoring the route, display the corresponding directory content in the left menu * fix: modify review code
1 parent 2921f59 commit 390563d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

examples/sites/src/views/layout/layout.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<script>
5858
import { useRoute } from 'vue-router'
59-
import { defineComponent, reactive, computed, toRefs, onMounted, onUnmounted } from 'vue'
59+
import { defineComponent, reactive, computed, toRefs, watch, onMounted, onUnmounted } from 'vue'
6060
import { TreeMenu, Dropdown, DropdownMenu, Tooltip, Tag, Radio, RadioGroup, Button } from '@opentiny/vue'
6161
import { genMenus, getMenuIcons } from '@/menus.jsx'
6262
import { router } from '@/router.js'
@@ -96,6 +96,7 @@ export default defineComponent({
9696
})
9797
9898
const lang = getWord('zh-CN', 'en-US')
99+
const route = useRoute()
99100
const { all: allPathParam, theme = defaultTheme } = useRoute().params
100101
const allPath = allPathParam ? allPathParam + '/' : ''
101102
const getTo = (route, key) => `${import.meta.env.VITE_CONTEXT}${allPath}${lang}/${theme}/${route}${key}`
@@ -128,6 +129,19 @@ export default defineComponent({
128129
}
129130
let routerCbDestroy = null
130131
132+
watch(
133+
() => route.path,
134+
(currentVal) => {
135+
// 监听路由变化,反作用与左侧列表菜单展开对应的列表
136+
const list = currentVal.split('/')
137+
if (list && list[list.length - 1]) {
138+
const key = list[list.length - 1]
139+
state.expandKeys = [key]
140+
state.treeMenuRef.setCurrentKey(key)
141+
}
142+
}
143+
)
144+
131145
onMounted(async () => {
132146
// 每次切换路由,有锚点则跳转到锚点,否则导航到顶部
133147
routerCbDestroy = router.afterEach((to) => {

0 commit comments

Comments
 (0)