Commit 1f7905d450a4ce994ea51d339dbff8c606f41577
1 parent
e549c92b
fixed bug of menu when use recursive components and set accordion
Showing
3 changed files
with
14 additions
and
4 deletions
Show diff stats
examples/routers/menu.vue
... | ... | @@ -44,13 +44,14 @@ |
44 | 44 | <MenuItem name="5-4">Option 12</MenuItem> |
45 | 45 | </Submenu> |
46 | 46 | </Menu> |
47 | - <!-- <Menu theme="dark" accordion @on-open-change="handleOpenChange"> | |
47 | + <br/> | |
48 | + <Menu ref="menu2" theme="dark" accordion :open-names="openNames2" @on-open-change="handleOpenChange"> | |
48 | 49 | <template v-for="item in menuList"> |
49 | 50 | <custem-menu-item v-if="item.children" :key="`menu-${item.name}`" :parent-item="item"></custem-menu-item> |
50 | 51 | <menu-item v-else :name="`${item.name}`" :key="`menu-${item.name}`">{{ item.name }}</menu-item> |
51 | 52 | </template> |
52 | 53 | </Menu> |
53 | - <Button @click="addNewItem">添加菜单项</Button> --> | |
54 | + <Button @click="addNewItem">添加菜单项</Button> | |
54 | 55 | <Button @click="changeActive">修改激活项</Button> |
55 | 56 | <Button @click="setOpenNames">修改展开数组</Button> |
56 | 57 | <Menu mode="horizontal" theme="light" :active-name="activeName" @on-open-change="hc"> |
... | ... | @@ -108,6 +109,7 @@ import custemMenuItem from './custem-menu-item.vue' |
108 | 109 | data () { |
109 | 110 | return { |
110 | 111 | openNames: ['1'], |
112 | + openNames2: [], | |
111 | 113 | menuList: [ |
112 | 114 | { |
113 | 115 | name: '111', |
... | ... | @@ -184,8 +186,10 @@ import custemMenuItem from './custem-menu-item.vue' |
184 | 186 | }, |
185 | 187 | setOpenNames () { |
186 | 188 | this.openNames = ['2', '3']; |
189 | + this.openNames2 = ['222', '222-222', '222-222-222', '222-222-222-111'] | |
187 | 190 | this.$nextTick(() => { |
188 | 191 | this.$refs.menu.updateOpened(); |
192 | + this.$refs.menu2.updateOpened(); | |
189 | 193 | }) |
190 | 194 | }, |
191 | 195 | addNewItem () { | ... | ... |
src/components/menu/menu.vue
... | ... | @@ -79,6 +79,9 @@ |
79 | 79 | updateOpenKeys (name) { |
80 | 80 | let names = [...this.openedNames]; |
81 | 81 | const index = names.indexOf(name); |
82 | + if (this.accordion) findComponentsDownward(this, 'Submenu').forEach(item => { | |
83 | + item.opened = false; | |
84 | + }); | |
82 | 85 | if (index >= 0) { |
83 | 86 | let currentSubmenu = null; |
84 | 87 | findComponentsDownward(this, 'Submenu').forEach(item => { |
... | ... | @@ -87,11 +90,14 @@ |
87 | 90 | item.opened = false; |
88 | 91 | } |
89 | 92 | }); |
93 | + findComponentsUpward(currentSubmenu, 'Submenu').forEach(item => { | |
94 | + item.opened = true; | |
95 | + }); | |
90 | 96 | findComponentsDownward(currentSubmenu, 'Submenu').forEach(item => { |
91 | 97 | item.opened = false; |
92 | 98 | }); |
93 | 99 | } else { |
94 | - if (this.mode === 'horizontal' && this.accordion) { | |
100 | + if (this.accordion) { | |
95 | 101 | let currentSubmenu = null; |
96 | 102 | findComponentsDownward(this, 'Submenu').forEach(item => { |
97 | 103 | if (item.name === name) { | ... | ... |
src/components/select/select.vue
... | ... | @@ -427,7 +427,7 @@ |
427 | 427 | let initialValue = Array.isArray(value) ? value : [value]; |
428 | 428 | if (!multiple && (typeof initialValue[0] === 'undefined' || (String(initialValue[0]).trim() === '' && !Number.isFinite(initialValue[0])))) initialValue = []; |
429 | 429 | return initialValue.filter((item) => { |
430 | - return Boolean(item) || item === 0 | |
430 | + return Boolean(item) || item === 0; | |
431 | 431 | }); |
432 | 432 | }, |
433 | 433 | processOption(option, values, isFocused){ | ... | ... |