소스 검색

fix first enter do not active the menu bug (#2399)

baiyaaaaa 8 년 전
부모
커밋
ef06717f64
1개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      packages/menu/src/menu.vue

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

@@ -57,6 +57,15 @@
       },
       defaultOpeneds(value) {
         this.openedMenus = value;
+      },
+      '$route': {
+        immediate: true,
+        handler(value) {
+          if (this.router) {
+            this.activedIndex = value.path;
+            this.initOpenedMenu();
+          }
+        }
       }
     },
     methods: {
@@ -100,7 +109,7 @@
       },
       handleItemClick(item) {
         let { index, indexPath } = item;
-        this.activedIndex = item.index;
+
         this.$emit('select', index, indexPath, item);
 
         if (this.mode === 'horizontal') {
@@ -109,6 +118,8 @@
 
         if (this.router) {
           this.routeToItem(item);
+        } else {
+          this.activedIndex = item.index;
         }
       },
       // 初始化展开菜单