From b3b4134d8bc53a6901e64f7a25809e560230af01 Mon Sep 17 00:00:00 2001 From: zhigang.li Date: Wed, 4 Apr 2018 12:01:29 +0800 Subject: [PATCH] fixed https://github.com/iview/iview/issues/3298 --- examples/routers/menu.vue | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------- src/components/menu/menu.vue | 29 +++++++++++++++++------------ 2 files changed, 79 insertions(+), 51 deletions(-) diff --git a/examples/routers/menu.vue b/examples/routers/menu.vue index b2507e2..4138919 100644 --- a/examples/routers/menu.vue +++ b/examples/routers/menu.vue @@ -1,46 +1,69 @@ diff --git a/src/components/menu/menu.vue b/src/components/menu/menu.vue index 187859a..e5b5abe 100644 --- a/src/components/menu/menu.vue +++ b/src/components/menu/menu.vue @@ -43,7 +43,8 @@ }, data () { return { - currentActiveName: this.activeName + currentActiveName: this.activeName, + openedNames: [] }; }, computed: { @@ -76,36 +77,40 @@ this.broadcast('MenuItem', 'on-update-active-name', this.currentActiveName); }, updateOpenKeys (name) { - const index = this.openNames.indexOf(name); - if (index > -1) { - this.openNames.splice(index, 1); + let names = [...this.openedNames]; + const index = names.indexOf(name); + if (index >= 0) { + names.splice(index, 1); } else { - this.openNames.push(name); if (this.accordion) { - let currentSubmenu = {}; + let currentSubmenu = null; findComponentsDownward(this, 'Submenu').forEach(item => { if (item.name === name) currentSubmenu = item; }); findBrothersComponents(currentSubmenu, 'Submenu').forEach(item => { - let index = this.openNames.indexOf(item.name); - this.openNames.splice(index, index >= 0 ? 1 : 0); + let i = names.indexOf(item.name); + if (i >= 0) names.splice(i, 1); }); - this.openNames.push(name); + names.push(name); } } + this.openedNames = names; + this.$emit('on-open-change', this.openedNames); }, updateOpened () { const items = findComponentsDownward(this, 'Submenu'); if (items.length) { items.forEach(item => { - if (this.openNames.indexOf(item.name) > -1) item.opened = true; + if (this.openedNames.indexOf(item.name) > -1) item.opened = true; + else item.opened = false; }); } } }, mounted () { this.updateActiveName(); + this.openedNames = [...this.openNames]; this.updateOpened(); this.$on('on-menu-item-select', (name) => { this.currentActiveName = name; @@ -113,8 +118,8 @@ }); }, watch: { - openNames () { - this.$emit('on-open-change', this.openNames); + openNames (names) { + this.openedNames = names; }, activeName (val) { this.currentActiveName = val; -- libgit2 0.21.4