fix: 修复多级菜单高亮问题 (#459)

This commit is contained in:
liweijie0812 2023-03-29 14:35:47 +08:00 committed by GitHub
parent 4293d30180
commit ba9a918d99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,7 +38,6 @@ const props = defineProps({
default: () => [], default: () => [],
}, },
}); });
const active = computed(() => getActive()); const active = computed(() => getActive());
const list = computed(() => { const list = computed(() => {
@ -85,9 +84,16 @@ const getHref = (item: MenuRoute) => {
}; };
const getPath = (item: ListItemType) => { const getPath = (item: ListItemType) => {
const activeLevel = active.value.split('/').length;
const pathLevel = item.path.split('/').length;
if (activeLevel > pathLevel && active.value.startsWith(item.path)) {
return active.value;
}
if (active.value === item.path) { if (active.value === item.path) {
return active.value; return active.value;
} }
return item.meta?.single ? item.redirect : item.path; return item.meta?.single ? item.redirect : item.path;
}; };