From b2d676bd83d2df9d9c0d8003c6afd245d6db450c Mon Sep 17 00:00:00 2001 From: zhigang.li Date: Mon, 22 Jan 2018 13:12:15 +0800 Subject: [PATCH] fixed the bug about styles when mode is 'horizontal' of menu --- examples/routers/menu.vue | 16 +++++++++++++--- src/components/menu/menu-group.vue | 2 +- src/components/menu/menu-item.vue | 2 +- src/components/menu/mixin.js | 8 ++++++++ src/components/menu/submenu.vue | 14 +++++--------- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/examples/routers/menu.vue b/examples/routers/menu.vue index 46b0993..964b454 100644 --- a/examples/routers/menu.vue +++ b/examples/routers/menu.vue @@ -1,6 +1,6 @@ 二级1 二级2 - + + + + Group-item1 + + + + Group-item2 + + + diff --git a/src/components/menu/menu-group.vue b/src/components/menu/menu-group.vue index 8b001fc..9611320 100644 --- a/src/components/menu/menu-group.vue +++ b/src/components/menu/menu-group.vue @@ -25,7 +25,7 @@ }, computed: { groupStyle () { - return this.hasParentSubmenu ? { + return this.hasParentSubmenu && this.mode !== 'horizontal' ? { paddingLeft: 43 + (this.parentSubmenuNum - 1) * 28 + 'px' } : {}; } diff --git a/src/components/menu/menu-item.vue b/src/components/menu/menu-item.vue index 074192b..168aae7 100644 --- a/src/components/menu/menu-item.vue +++ b/src/components/menu/menu-item.vue @@ -37,7 +37,7 @@ ]; }, itemStyle () { - return this.hasParentSubmenu ? { + return this.hasParentSubmenu && this.mode !== 'horizontal' ? { paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px' } : {}; } diff --git a/src/components/menu/mixin.js b/src/components/menu/mixin.js index 630c303..6d5e29e 100644 --- a/src/components/menu/mixin.js +++ b/src/components/menu/mixin.js @@ -1,11 +1,19 @@ import { findComponentUpward, findComponentsUpward } from '../../utils/assist'; export default { + data () { + return { + menu: findComponentUpward(this, 'Menu') + }; + }, computed: { hasParentSubmenu () { return findComponentUpward(this, 'Submenu'); }, parentSubmenuNum () { return findComponentsUpward(this, 'Submenu').length; + }, + mode () { + return this.menu.mode; } } }; \ No newline at end of file diff --git a/src/components/menu/submenu.vue b/src/components/menu/submenu.vue index d010450..569d3e0 100644 --- a/src/components/menu/submenu.vue +++ b/src/components/menu/submenu.vue @@ -46,8 +46,7 @@ prefixCls: prefixCls, active: false, opened: false, - dropWidth: parseFloat(getStyle(this.$el, 'width')), - parent: findComponentUpward(this, 'Menu') + dropWidth: parseFloat(getStyle(this.$el, 'width')) }; }, computed: { @@ -63,11 +62,8 @@ } ]; }, - mode () { - return this.parent.mode; - }, accordion () { - return this.parent.accordion; + return this.menu.accordion; }, dropStyle () { let style = {}; @@ -88,7 +84,7 @@ clearTimeout(this.timeout); this.timeout = setTimeout(() => { - this.parent.updateOpenKeys(this.name); + this.menu.updateOpenKeys(this.name); this.opened = true; }, 250); }, @@ -98,7 +94,7 @@ clearTimeout(this.timeout); this.timeout = setTimeout(() => { - this.parent.updateOpenKeys(this.name); + this.menu.updateOpenKeys(this.name); this.opened = false; }, 150); }, @@ -112,7 +108,7 @@ }); } this.opened = !opened; - this.parent.updateOpenKeys(this.name); + this.menu.updateOpenKeys(this.name); } }, watch: { -- libgit2 0.21.4