move computed value parentSubmenuNum from .vue to mixin.js
This commit is contained in:
parent
a163daa07a
commit
acba45fed5
3 changed files with 14 additions and 10 deletions
|
@ -3,12 +3,13 @@
|
|||
</template>
|
||||
<script>
|
||||
import Emitter from '../../mixins/emitter';
|
||||
import { findComponentUpward, findComponentsUpward } from '../../utils/assist';
|
||||
import { findComponentUpward } from '../../utils/assist';
|
||||
const prefixCls = 'ivu-menu';
|
||||
import mixin from './mixin';
|
||||
|
||||
export default {
|
||||
name: 'MenuItem',
|
||||
mixins: [ Emitter ],
|
||||
mixins: [ Emitter, mixin ],
|
||||
props: {
|
||||
name: {
|
||||
type: [String, Number],
|
||||
|
@ -35,9 +36,6 @@
|
|||
}
|
||||
];
|
||||
},
|
||||
parentSubmenuNum () {
|
||||
return findComponentsUpward(this, 'Submenu').length;
|
||||
},
|
||||
itemStyle () {
|
||||
return this.hasParentSubmenu ? {
|
||||
paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
|
||||
|
|
8
src/components/menu/mixin.js
Normal file
8
src/components/menu/mixin.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { findComponentsUpward } from '../../utils/assist';
|
||||
export default {
|
||||
computed: {
|
||||
parentSubmenuNum () {
|
||||
return findComponentsUpward(this, 'Submenu').length;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,14 +21,15 @@
|
|||
import Drop from '../select/dropdown.vue';
|
||||
import Icon from '../icon/icon.vue';
|
||||
import CollapseTransition from '../base/collapse-transition';
|
||||
import { getStyle, findComponentUpward, findComponentsUpward, findComponentsDownward } from '../../utils/assist';
|
||||
import { getStyle, findComponentUpward, findComponentsDownward } from '../../utils/assist';
|
||||
import Emitter from '../../mixins/emitter';
|
||||
import mixin from './mixin';
|
||||
|
||||
const prefixCls = 'ivu-menu';
|
||||
|
||||
export default {
|
||||
name: 'Submenu',
|
||||
mixins: [ Emitter ],
|
||||
mixins: [ Emitter, mixin ],
|
||||
components: { Icon, Drop, CollapseTransition },
|
||||
props: {
|
||||
name: {
|
||||
|
@ -77,9 +78,6 @@
|
|||
hasParentSubmenu () {
|
||||
return findComponentUpward(this, 'Submenu');
|
||||
},
|
||||
parentSubmenuNum () {
|
||||
return findComponentsUpward(this, 'Submenu').length;
|
||||
},
|
||||
titleStyle () {
|
||||
return this.hasParentSubmenu ? {
|
||||
paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
|
||||
|
|
Loading…
Add table
Reference in a new issue