Kaynağa Gözat

样式激活菜单

zhangningning 2 hafta önce
ebeveyn
işleme
c3f60495ba
1 değiştirilmiş dosya ile 11 ekleme ve 1 silme
  1. 11 1
      src/App.vue

+ 11 - 1
src/App.vue

@@ -49,10 +49,20 @@ const route = useRoute()
 const router = useRouter()
 
 
-const activeIndex = ref('1')
 function goMyLearning() {
   router.push('/my-learning')
 }
+// 将 activeIndex 改为响应式,并根据当前路由动态计算
+const activeIndex = computed(() => {
+  switch (route.path) {
+    case '/':
+      return '1'
+    case '/my-learning':
+      return '2'
+    default:
+      return '1' // 默认返回首页
+  }
+})
 </script>
 
 <style lang="scss">