From 0aafce7f6be4d745bc661e17b8eea89286de2de3 Mon Sep 17 00:00:00 2001 From: GeDer <1185202122@qq.com> Date: Thu, 28 Aug 2025 09:30:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=BD=93=E5=89=8D=E8=8F=9C=E5=8D=95=E4=B8=8E?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TreeMenu/index.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/TreeMenu/index.vue b/src/components/TreeMenu/index.vue index 5370f96..464fba2 100644 --- a/src/components/TreeMenu/index.vue +++ b/src/components/TreeMenu/index.vue @@ -1,5 +1,5 @@ @@ -21,12 +21,30 @@ export default { isCollapse: false, menuData: menuData || [] }; + }, + computed: { + /** + * 计算当前路由路径,用于设置菜单的默认激活项 + * @returns {string} 当前路由路径 + */ + currentRoutePath() { + // 对于Vue Router 3,使用this.$route.path获取当前路径 + return this.$route ? this.$route.path : '/index'; + } }, methods: { toggleAside() { this.isCollapse = !this.isCollapse } + }, + watch: { + /** + * 监听路由变化,确保菜单激活项正确更新 + */ + '$route'(to, from) { + console.log('路由变化:', from.path, '->', to.path); + } } }; -- Gitee