fix(menu): 修复菜单展开逻辑,确保选中元素正确显示

This commit is contained in:
严浩
2025-10-24 12:31:23 +08:00
parent c11473edb5
commit 6fcd0c54e8

View File

@@ -135,8 +135,8 @@ export function useMetaLayoutsNMenuOptions({ menuInstRef }: { menuInstRef: Ref<M
watch( watch(
() => router.currentRoute.value.path, () => router.currentRoute.value.path,
(newPath) => { (newPath) => {
menuInstRef.value?.showOption(newPath);
selectedKey.value = newPath; selectedKey.value = newPath;
menuInstRef.value?.showOption(newPath); // 展开菜单,确保设定的元素被显示,如果不传入 key 会展示当前选中元素
}, },
{ immediate: true }, { immediate: true },
); );
@@ -146,5 +146,6 @@ export function useMetaLayoutsNMenuOptions({ menuInstRef }: { menuInstRef: Ref<M
return { return {
options, options,
selectedKey, selectedKey,
// expanded-keys // 展开的子菜单标识符数组如果设定了菜单的展开将会进入受控状态default-expanded-keys 不会生效
}; };
} }