From ab673ebc6b7864127c0c5fa232fad73a21363cfa Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Thu, 8 Dec 2016 13:29:49 +0800 Subject: [PATCH] update Menu --- src/components/menu/menu.vue | 18 +++++++++++++++++- src/components/menu/submenu.vue | 3 +++ test/routers/menu.vue | 5 ++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/components/menu/menu.vue b/src/components/menu/menu.vue index ec747f7..4b6f61d 100644 --- a/src/components/menu/menu.vue +++ b/src/components/menu/menu.vue @@ -24,7 +24,10 @@ type: [String, Number] }, openKeys: { - type: Array + type: Array, + default () { + return [] + } }, accordion: { type: Boolean, @@ -81,6 +84,14 @@ item.active = item.key === this.activeKey; } }) + }, + updateOpenKeys (key) { + const index = this.openKeys.indexOf(key); + if (index > -1) { + this.openKeys.splice(index, 1); + } else { + this.openKeys.push(key); + } } }, compiled () { @@ -92,6 +103,11 @@ this.updateActiveKey(); this.$emit('on-select', key); } + }, + watch: { + openKeys () { + this.$emit('on-open-change', this.openKeys); + } } } \ No newline at end of file diff --git a/src/components/menu/submenu.vue b/src/components/menu/submenu.vue index 5a47e3b..cdeedb8 100644 --- a/src/components/menu/submenu.vue +++ b/src/components/menu/submenu.vue @@ -58,6 +58,7 @@ clearTimeout(this.timeout); this.timeout = setTimeout(() => { + this.$parent.updateOpenKeys(this.key); this.opened = true; }, 250); }, @@ -67,6 +68,7 @@ clearTimeout(this.timeout); this.timeout = setTimeout(() => { + this.$parent.updateOpenKeys(this.key); this.opened = false; }, 150); }, @@ -80,6 +82,7 @@ }); } this.opened = !opened; + this.$parent.updateOpenKeys(this.key); } }, watch: { diff --git a/test/routers/menu.vue b/test/routers/menu.vue index f9986fb..ba5353b 100644 --- a/test/routers/menu.vue +++ b/test/routers/menu.vue @@ -19,7 +19,7 @@ 导航四

- + 导航一 @@ -121,6 +121,9 @@ methods: { toggleMode () { this.mode = this.mode === 'horizontal' ? 'vertical' : 'horizontal'; + }, + change (d) { + console.log(d) } } } -- libgit2 0.21.4