Commit acba45fed5adf8d6a21204150efabfbfbddd0f2c
1 parent
a163daa0
move computed value parentSubmenuNum from .vue to mixin.js
Showing
3 changed files
with
14 additions
and
10 deletions
Show diff stats
src/components/menu/menu-item.vue
@@ -3,12 +3,13 @@ | @@ -3,12 +3,13 @@ | ||
3 | </template> | 3 | </template> |
4 | <script> | 4 | <script> |
5 | import Emitter from '../../mixins/emitter'; | 5 | import Emitter from '../../mixins/emitter'; |
6 | - import { findComponentUpward, findComponentsUpward } from '../../utils/assist'; | 6 | + import { findComponentUpward } from '../../utils/assist'; |
7 | const prefixCls = 'ivu-menu'; | 7 | const prefixCls = 'ivu-menu'; |
8 | + import mixin from './mixin'; | ||
8 | 9 | ||
9 | export default { | 10 | export default { |
10 | name: 'MenuItem', | 11 | name: 'MenuItem', |
11 | - mixins: [ Emitter ], | 12 | + mixins: [ Emitter, mixin ], |
12 | props: { | 13 | props: { |
13 | name: { | 14 | name: { |
14 | type: [String, Number], | 15 | type: [String, Number], |
@@ -35,9 +36,6 @@ | @@ -35,9 +36,6 @@ | ||
35 | } | 36 | } |
36 | ]; | 37 | ]; |
37 | }, | 38 | }, |
38 | - parentSubmenuNum () { | ||
39 | - return findComponentsUpward(this, 'Submenu').length; | ||
40 | - }, | ||
41 | itemStyle () { | 39 | itemStyle () { |
42 | return this.hasParentSubmenu ? { | 40 | return this.hasParentSubmenu ? { |
43 | paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px' | 41 | paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px' |
src/components/menu/submenu.vue
@@ -21,14 +21,15 @@ | @@ -21,14 +21,15 @@ | ||
21 | import Drop from '../select/dropdown.vue'; | 21 | import Drop from '../select/dropdown.vue'; |
22 | import Icon from '../icon/icon.vue'; | 22 | import Icon from '../icon/icon.vue'; |
23 | import CollapseTransition from '../base/collapse-transition'; | 23 | import CollapseTransition from '../base/collapse-transition'; |
24 | - import { getStyle, findComponentUpward, findComponentsUpward, findComponentsDownward } from '../../utils/assist'; | 24 | + import { getStyle, findComponentUpward, findComponentsDownward } from '../../utils/assist'; |
25 | import Emitter from '../../mixins/emitter'; | 25 | import Emitter from '../../mixins/emitter'; |
26 | + import mixin from './mixin'; | ||
26 | 27 | ||
27 | const prefixCls = 'ivu-menu'; | 28 | const prefixCls = 'ivu-menu'; |
28 | 29 | ||
29 | export default { | 30 | export default { |
30 | name: 'Submenu', | 31 | name: 'Submenu', |
31 | - mixins: [ Emitter ], | 32 | + mixins: [ Emitter, mixin ], |
32 | components: { Icon, Drop, CollapseTransition }, | 33 | components: { Icon, Drop, CollapseTransition }, |
33 | props: { | 34 | props: { |
34 | name: { | 35 | name: { |
@@ -77,9 +78,6 @@ | @@ -77,9 +78,6 @@ | ||
77 | hasParentSubmenu () { | 78 | hasParentSubmenu () { |
78 | return findComponentUpward(this, 'Submenu'); | 79 | return findComponentUpward(this, 'Submenu'); |
79 | }, | 80 | }, |
80 | - parentSubmenuNum () { | ||
81 | - return findComponentsUpward(this, 'Submenu').length; | ||
82 | - }, | ||
83 | titleStyle () { | 81 | titleStyle () { |
84 | return this.hasParentSubmenu ? { | 82 | return this.hasParentSubmenu ? { |
85 | paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px' | 83 | paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px' |