From f6d419b94fb3363ce9a9763521ecd1e7c227400c Mon Sep 17 00:00:00 2001 From: yiran <239559238@qq.com> Date: Mon, 25 Jul 2022 18:20:16 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E9=85=8D=E7=BD=AEactiveMenu=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/jekip/naive-ui-admin/issues/151 --- src/layout/components/Menu/index.vue | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/layout/components/Menu/index.vue b/src/layout/components/Menu/index.vue index 5969834..9b07fe5 100644 --- a/src/layout/components/Menu/index.vue +++ b/src/layout/components/Menu/index.vue @@ -99,13 +99,16 @@ () => currentRoute.fullPath, () => { updateMenu(); - const matched = currentRoute.matched; - state.openKeys = matched.map((item) => item.name); - const activeMenu: string = (currentRoute.meta?.activeMenu as string) || ''; - selectedKeys.value = activeMenu ? (activeMenu as string) : (currentRoute.name as string); } ); + function updateSelectedKeys() { + const matched = currentRoute.matched; + state.openKeys = matched.map((item) => item.name); + const activeMenu: string = (currentRoute.meta?.activeMenu as string) || ''; + selectedKeys.value = activeMenu ? (activeMenu as string) : (currentRoute.name as string); + } + function updateMenu() { if (!settingStore.menuSetting.mixMenu) { menus.value = generatorMenu(asyncRouteStore.getMenus); @@ -116,6 +119,7 @@ const activeMenu: string = currentRoute?.matched[0].meta?.activeMenu as string; headerMenuSelectKey.value = (activeMenu ? activeMenu : firstRouteName) || ''; } + updateSelectedKeys(); } // 点击菜单