Преглед изворни кода

fix menu router prop bug when vertical mode

baiyaaaaa пре 8 година
родитељ
комит
30003ec594
3 измењених фајлова са 10 додато и 5 уклоњено
  1. 1 0
      CHANGELOG.md
  2. 1 1
      packages/menu/src/menu-item.vue
  3. 8 4
      packages/menu/src/menu.vue

+ 1 - 0
CHANGELOG.md

@@ -15,6 +15,7 @@
 - 为 Tree 添加 getCheckedNodes 方法和 node-click、check-change 回调
 - 新增 DatePicker 禁用日期功能 #253
 - 修复 多选可搜索的 Select 下拉选项自动展开的问题
+- 修复 Menu 组件垂直模式下开启 router 属性会立刻跳转的问题 #295
 
 #### 非兼容性更新
 

+ 1 - 1
packages/menu/src/menu-item.vue

@@ -28,7 +28,7 @@
     },
     methods: {
       handleClick() {
-        this.rootMenu.handleSelect(this.index, this.indexPath, this.route);
+        this.rootMenu.handleSelect(this.index, this.indexPath, this.route || this.index);
       }
     },
     created() {

+ 8 - 4
packages/menu/src/menu.vue

@@ -99,17 +99,21 @@
           });
         }
 
-        if (this.router) {
-          this.$router.push(route || index);
+        if (this.router && route) {
+          this.$router.push(route);
         }
       }
     },
     mounted() {
       let index = this.activeIndex;
-      if (index) {
+      if (index && this.mode === 'vertical') {
         let indexPath = this.menuItems[index].indexPath;
 
-        this.handleSelect(index, indexPath);
+        // 展开该菜单项的路径上所有子菜单
+        indexPath.forEach(index => {
+          let submenu = this.submenus[index];
+          submenu && this.openMenu(index, submenu.indexPath);
+        });
       }
     }
   };