Skip to content

fix: by monitoring the route, display the corresponding directory content in the left menu #2278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion examples/sites/src/views/layout/layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<script>
import { useRoute } from 'vue-router'
import { defineComponent, reactive, computed, toRefs, onMounted, onUnmounted } from 'vue'
import { defineComponent, reactive, computed, toRefs, watch, onMounted, onUnmounted } from 'vue'
import { TreeMenu, Dropdown, DropdownMenu, Tooltip, Tag, Radio, RadioGroup, Button } from '@opentiny/vue'
import { genMenus, getMenuIcons } from '@/menus.jsx'
import { router } from '@/router.js'
Expand Down Expand Up @@ -96,6 +96,7 @@ export default defineComponent({
})

const lang = getWord('zh-CN', 'en-US')
const route = useRoute()
const { all: allPathParam, theme = defaultTheme } = useRoute().params
const allPath = allPathParam ? allPathParam + '/' : ''
const getTo = (route, key) => `${import.meta.env.VITE_CONTEXT}${allPath}${lang}/${theme}/${route}${key}`
Expand Down Expand Up @@ -128,6 +129,19 @@ export default defineComponent({
}
let routerCbDestroy = null

watch(
() => route.path,
(currentVal) => {
// 监听路由变化,反作用与左侧列表菜单展开对应的列表
const list = currentVal.split('/')
if (list && list[list.length - 1]) {
const key = list[list.length - 1]
state.expandKeys = [key]
state.treeMenuRef.setCurrentKey(key)
}
}
)

onMounted(async () => {
// 每次切换路由,有锚点则跳转到锚点,否则导航到顶部
routerCbDestroy = router.afterEach((to) => {
Expand Down
Loading