Skip to content

Commit

Permalink
Merge pull request #3803 from lison16/su
Browse files Browse the repository at this point in the history
fixed bug of menu when use recursive components and set accordion
  • Loading branch information
icarusion committed Jun 5, 2018
2 parents 9aacb4c + 1f7905d commit bae9f44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions examples/routers/menu.vue
Expand Up @@ -44,13 +44,14 @@
<MenuItem name="5-4">Option 12</MenuItem>
</Submenu>
</Menu>
<!-- <Menu theme="dark" accordion @on-open-change="handleOpenChange">
<br/>
<Menu ref="menu2" theme="dark" accordion :open-names="openNames2" @on-open-change="handleOpenChange">
<template v-for="item in menuList">
<custem-menu-item v-if="item.children" :key="`menu-${item.name}`" :parent-item="item"></custem-menu-item>
<menu-item v-else :name="`${item.name}`" :key="`menu-${item.name}`">{{ item.name }}</menu-item>
</template>
</Menu>
<Button @click="addNewItem">添加菜单项</Button> -->
<Button @click="addNewItem">添加菜单项</Button>
<Button @click="changeActive">修改激活项</Button>
<Button @click="setOpenNames">修改展开数组</Button>
<Menu mode="horizontal" theme="light" :active-name="activeName" @on-open-change="hc">
Expand Down Expand Up @@ -108,6 +109,7 @@ import custemMenuItem from './custem-menu-item.vue'
data () {
return {
openNames: ['1'],
openNames2: [],
menuList: [
{
name: '111',
Expand Down Expand Up @@ -184,8 +186,10 @@ import custemMenuItem from './custem-menu-item.vue'
},
setOpenNames () {
this.openNames = ['2', '3'];
this.openNames2 = ['222', '222-222', '222-222-222', '222-222-222-111']
this.$nextTick(() => {
this.$refs.menu.updateOpened();
this.$refs.menu2.updateOpened();
})
},
addNewItem () {
Expand Down
8 changes: 7 additions & 1 deletion src/components/menu/menu.vue
Expand Up @@ -79,6 +79,9 @@
updateOpenKeys (name) {
let names = [...this.openedNames];
const index = names.indexOf(name);
if (this.accordion) findComponentsDownward(this, 'Submenu').forEach(item => {
item.opened = false;
});
if (index >= 0) {
let currentSubmenu = null;
findComponentsDownward(this, 'Submenu').forEach(item => {
Expand All @@ -87,11 +90,14 @@
item.opened = false;
}
});
findComponentsUpward(currentSubmenu, 'Submenu').forEach(item => {
item.opened = true;
});
findComponentsDownward(currentSubmenu, 'Submenu').forEach(item => {
item.opened = false;
});
} else {
if (this.mode === 'horizontal' && this.accordion) {
if (this.accordion) {
let currentSubmenu = null;
findComponentsDownward(this, 'Submenu').forEach(item => {
if (item.name === name) {
Expand Down

0 comments on commit bae9f44

Please sign in to comment.