杨宽 3 роки тому
батько
коміт
ad0fb2a594
2 змінених файлів з 34 додано та 34 видалено
  1. 13 13
      src/views/layout/Header.vue
  2. 21 21
      src/views/layout/Menu.vue

+ 13 - 13
src/views/layout/Header.vue

@@ -104,19 +104,19 @@ export default {
       return data.isActive ? "active" : "";
     },
   },
-  // watch: {
-  //   $route: {
-  //     handler: function(val, oldVal) {
-  //       this.menus.some((t, index) => {
-  //         if (t.id == val.query.root) {
-  //           this.activeIndex = index;
-  //         }
-  //       });
-  //     },
-  //     //深度观察监听
-  //     deep: true,
-  //   },
-  // },
+  watch: {
+    $route: {
+      handler: function(val, oldVal) {
+        this.menus.some((t, index) => {
+          if (t.id == val.query.root) {
+            this.activeIndex = index;
+          }
+        });
+      },
+      //深度观察监听
+      deep: true,
+    },
+  },
 };
 </script>
 

+ 21 - 21
src/views/layout/Menu.vue

@@ -209,21 +209,21 @@ export default {
     },
   },
   watch: {
-    //监听路由
-    // $route: {
-    //   handler: function(val, oldVal) {
-    //     if (val.query.root) this.currRoot = val.query.root;
+    // 监听路由
+    $route: {
+      handler: function(val, oldVal) {
+        if (val.query.root) this.currRoot = val.query.root;
 
-    //     this.currentMenu.some((element, index) => {
-    //       if (element.path == val.path) {
-    //         this.activeIndex = index;
-    //         return true;
-    //       }
-    //     });
-    //   },
-    //   //深度观察监听
-    //   deep: true,
-    // },
+        this.currentMenu.some((element, index) => {
+          if (element.path == val.path) {
+            this.activeIndex = index;
+            return true;
+          }
+        });
+      },
+      //深度观察监听
+      deep: true,
+    },
     root: {
       handler: function(val, oldVal) {
         this.currRoot = val;
@@ -235,13 +235,13 @@ export default {
           // 基于 root 和 currRoot 为一致
           // 进行页面刷新
           // 防止 刷新页面也同步执行切换页面逻辑
-          // if (this.root == this.currRoot) {
-          // this.activeIndex = 0;
-          // this.$router.push({
-          //   path: val[0].path,
-          //   query: { root: this.currRoot },
-          // });
-          // }
+          if (this.root == this.currRoot) {
+            this.activeIndex = 0;
+            this.$router.push({
+              path: val[0].path,
+              query: { root: this.currRoot },
+            });
+          }
         }
       },
     },