From b093f99ab5ac9f308c561c64aec6bc20092e488c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Fri, 9 Aug 2024 20:16:56 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E4=BB=8E=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=E7=82=B9=E5=87=BB=E6=9F=90=E4=B8=AA=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E5=88=86=E7=B1=BB=E9=A1=B5=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E5=88=99=E8=87=AA=E5=8A=A8=E9=80=89=E4=B8=AD=E5=B7=A6=E4=BE=A7?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E7=BA=A7=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/category.vue | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pages/index/category.vue b/pages/index/category.vue index cb87b0b5..619220b2 100644 --- a/pages/index/category.vue +++ b/pages/index/category.vue @@ -131,8 +131,16 @@ getGoodsList(); } - onLoad(async () => { + onLoad(async (params) => { await getList(); + // 从主页点进来的时候自动选中左侧一级菜单 + const cateList = state.categoryList + for (let index = 0; index < cateList.length;index++) { + if (cateList[index].id == params.id) { + state.activeMenu = index + break; + } + } // 如果是 first 风格,需要加载商品分页 if (state.style === 'first_one' || state.style === 'first_two') { onMenu(0); From fd83bcf02a3bf60e0a2441450060016e18a5d2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Fri, 9 Aug 2024 21:26:29 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=BF=9B=E5=85=A5=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA=E5=8A=A8=E5=8B=BE?= =?UTF-8?q?=E9=80=89=E5=B7=A6=E4=BE=A7=E4=B8=80=E7=BA=A7=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/category.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/index/category.vue b/pages/index/category.vue index 619220b2..52e46aaa 100644 --- a/pages/index/category.vue +++ b/pages/index/category.vue @@ -135,9 +135,9 @@ await getList(); // 从主页点进来的时候自动选中左侧一级菜单 const cateList = state.categoryList - for (let index = 0; index < cateList.length;index++) { + for (let index = 0; index < cateList.length; index++) { if (cateList[index].id == params.id) { - state.activeMenu = index + onMenu(index); break; } } From cc9f31f8c39e6c29bc3b416e67d8c92722e65793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Fri, 9 Aug 2024 22:06:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=BF=9B=E5=85=A5=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA=E5=8A=A8=E5=8B=BE?= =?UTF-8?q?=E9=80=89=E5=B7=A6=E4=BE=A7=E4=B8=80=E7=BA=A7=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/category.vue | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pages/index/category.vue b/pages/index/category.vue index 52e46aaa..b4ab3b00 100644 --- a/pages/index/category.vue +++ b/pages/index/category.vue @@ -133,14 +133,12 @@ onLoad(async (params) => { await getList(); - // 从主页点进来的时候自动选中左侧一级菜单 - const cateList = state.categoryList - for (let index = 0; index < cateList.length; index++) { - if (cateList[index].id == params.id) { - onMenu(index); - break; - } - } + + // 首页点击分类的处理:查找满足条件的分类 + const foundCategory = state.categoryList.find(category => category.id == params.id); + // 如果找到则调用 onMenu 自动勾选相应分类,否则调用 onMenu(0) 勾选第一个分类 + onMenu(foundCategory ? state.categoryList.indexOf(foundCategory) : 0); + // 如果是 first 风格,需要加载商品分页 if (state.style === 'first_one' || state.style === 'first_two') { onMenu(0);