menu-item.vue
2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
<li :class="classes" @click.stop="handleClick" :style="itemStyle"><slot></slot></li>
</template>
<script>
import Emitter from '../../mixins/emitter';
import { findComponentUpward } from '../../utils/assist';
const prefixCls = 'ivu-menu';
import mixin from './mixin';
export default {
name: 'MenuItem',
mixins: [ Emitter, mixin ],
props: {
name: {
type: [String, Number],
required: true
},
disabled: {
type: Boolean,
default: false
}
},
data () {
return {
active: false
};
},
computed: {
classes () {
return [
`${prefixCls}-item`,
{
[`${prefixCls}-item-active`]: this.active,
[`${prefixCls}-item-selected`]: this.active,
[`${prefixCls}-item-disabled`]: this.disabled
}
];
},
itemStyle () {
return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
} : {};
}
},
methods: {
handleClick () {
if (this.disabled) return;
let parent = findComponentUpward(this, 'Submenu');
if (parent) {
this.dispatch('Submenu', 'on-menu-item-select', this.name);
} else {
this.dispatch('Menu', 'on-menu-item-select', this.name);
}
}
},
mounted () {
this.$on('on-update-active-name', (name) => {
if (this.name === name) {
this.active = true;
this.dispatch('Submenu', 'on-update-active-name', name);
} else {
this.active = false;
}
});
}
};
</script>