From c2e9b169174b9f33d8b0e68ee15096f89dd7e65a Mon Sep 17 00:00:00 2001 From: hooray <304327508@qq.com> Date: Thu, 13 Oct 2022 14:15:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/menu.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/store/modules/menu.ts b/src/store/modules/menu.ts index e92669a2..eed64f56 100644 --- a/src/store/modules/menu.ts +++ b/src/store/modules/menu.ts @@ -190,15 +190,10 @@ const useMenuStore = defineStore( } else { // 如果是 string 类型,则认为是路由,需要查找对应的主导航索引 - this.allMenus.forEach((item, index) => { - if ( - item.children.some((r) => { - return data.indexOf(`${r.path}/`) === 0 || data === r.path - }) - ) { - this.actived = index - } - }) + const findIndex = this.allMenus.findIndex(item => item.children.some(r => data.indexOf(`${r.path}/`) === 0 || data === r.path)) + if (findIndex >= 0) { + this.actived = findIndex + } } }, },