diff --git a/src/components/TreeMenu/index.vue b/src/components/TreeMenu/index.vue index 5370f9607a5d2bba5c81e9ed7a1e8d15ad7b3213..464fba2e4ae49d7645d74f02bc613ce6468c80c8 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); + } } };