8778b343
梁灏
init Menu components
|
1
|
<template>
|
e05d7289
梁灏
update Menu
|
2
|
<ul :class="classes"><slot></slot></ul>
|
8778b343
梁灏
init Menu components
|
3
4
|
</template>
<script>
|
e05d7289
梁灏
update Menu
|
5
6
7
8
|
import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-menu';
|
8778b343
梁灏
init Menu components
|
9
|
export default {
|
e05d7289
梁灏
update Menu
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
props: {
mode: {
validator (value) {
return oneOf(value, ['horizontal', 'vertical']);
},
default: 'vertical'
},
theme: {
validator (value) {
return oneOf(value, ['light', 'dark', 'primary']);
},
default: 'light'
},
activeKey: {
type: [String, Number]
},
openKeys: {
|
ab673ebc
梁灏
update Menu
|
27
28
29
30
|
type: Array,
default () {
return []
}
|
e05d7289
梁灏
update Menu
|
31
32
33
34
35
36
|
},
accordion: {
type: Boolean,
default: false
}
},
|
8778b343
梁灏
init Menu components
|
37
|
data () {
|
e05d7289
梁灏
update Menu
|
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
70
71
72
73
74
75
76
77
78
|
return {
}
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-${this.mode}`]: this.mode,
[`${prefixCls}-${this.theme}`]: this.theme
}
]
}
},
methods: {
updateActiveKey () {
this.$children.forEach((item, index) => {
if (!this.activeKey && index === 0) this.activeKey = item.key;
if (item.$options.name === 'Submenu') {
item.active = false;
item.$children.forEach(subitem => {
if (subitem.$options.name === 'MenuGroup') {
subitem.$children.forEach(groupItem => {
if (groupItem.key === this.activeKey) {
groupItem.active = true;
groupItem.$parent.$parent.active = true;
} else {
groupItem.active = false;
}
})
} else {
if (subitem.key === this.activeKey) {
subitem.active = true;
subitem.$parent.active = true;
} else {
subitem.active = false;
}
}
})
|
0acdae19
梁灏
update Menu
|
79
80
81
82
|
} else if (item.$options.name === 'MenuGroup') {
item.$children.forEach(groupItem => {
groupItem.active = groupItem.key === this.activeKey;
})
|
e05d7289
梁灏
update Menu
|
83
84
85
86
|
} else {
item.active = item.key === this.activeKey;
}
})
|
ab673ebc
梁灏
update Menu
|
87
88
89
90
91
92
93
94
|
},
updateOpenKeys (key) {
const index = this.openKeys.indexOf(key);
if (index > -1) {
this.openKeys.splice(index, 1);
} else {
this.openKeys.push(key);
}
|
e05d7289
梁灏
update Menu
|
95
96
97
98
|
}
},
compiled () {
this.updateActiveKey();
|
8778b343
梁灏
init Menu components
|
99
|
},
|
e05d7289
梁灏
update Menu
|
100
101
102
103
104
105
|
events: {
'on-menu-item-select' (key) {
this.activeKey = key;
this.updateActiveKey();
this.$emit('on-select', key);
}
|
ab673ebc
梁灏
update Menu
|
106
107
108
109
110
|
},
watch: {
openKeys () {
this.$emit('on-open-change', this.openKeys);
}
|
e05d7289
梁灏
update Menu
|
111
|
}
|
8778b343
梁灏
init Menu components
|
112
113
|
}
</script>
|