update Menu

update Menu
This commit is contained in:
梁灏 2016-12-08 13:29:49 +08:00
parent 0acdae1983
commit ab673ebc6b
3 changed files with 24 additions and 2 deletions

View file

@ -24,7 +24,10 @@
type: [String, Number] type: [String, Number]
}, },
openKeys: { openKeys: {
type: Array type: Array,
default () {
return []
}
}, },
accordion: { accordion: {
type: Boolean, type: Boolean,
@ -81,6 +84,14 @@
item.active = item.key === this.activeKey; item.active = item.key === this.activeKey;
} }
}) })
},
updateOpenKeys (key) {
const index = this.openKeys.indexOf(key);
if (index > -1) {
this.openKeys.splice(index, 1);
} else {
this.openKeys.push(key);
}
} }
}, },
compiled () { compiled () {
@ -92,6 +103,11 @@
this.updateActiveKey(); this.updateActiveKey();
this.$emit('on-select', key); this.$emit('on-select', key);
} }
},
watch: {
openKeys () {
this.$emit('on-open-change', this.openKeys);
}
} }
} }
</script> </script>

View file

@ -58,6 +58,7 @@
clearTimeout(this.timeout); clearTimeout(this.timeout);
this.timeout = setTimeout(() => { this.timeout = setTimeout(() => {
this.$parent.updateOpenKeys(this.key);
this.opened = true; this.opened = true;
}, 250); }, 250);
}, },
@ -67,6 +68,7 @@
clearTimeout(this.timeout); clearTimeout(this.timeout);
this.timeout = setTimeout(() => { this.timeout = setTimeout(() => {
this.$parent.updateOpenKeys(this.key);
this.opened = false; this.opened = false;
}, 150); }, 150);
}, },
@ -80,6 +82,7 @@
}); });
} }
this.opened = !opened; this.opened = !opened;
this.$parent.updateOpenKeys(this.key);
} }
}, },
watch: { watch: {

View file

@ -19,7 +19,7 @@
<Menu-item key="4">导航四</Menu-item> <Menu-item key="4">导航四</Menu-item>
</Menu> </Menu>
<br><br> <br><br>
<Menu :mode="mode" active-key="1" accordion> <Menu :mode="mode" active-key="1" @on-open-change="change">
<Menu-item key="1"> <Menu-item key="1">
<Icon type="ionic"></Icon> <Icon type="ionic"></Icon>
<span>导航一</span> <span>导航一</span>
@ -121,6 +121,9 @@
methods: { methods: {
toggleMode () { toggleMode () {
this.mode = this.mode === 'horizontal' ? 'vertical' : 'horizontal'; this.mode = this.mode === 'horizontal' ? 'vertical' : 'horizontal';
},
change (d) {
console.log(d)
} }
} }
} }