update Dropdown

update Dropdown
This commit is contained in:
梁灏 2016-12-04 14:33:06 +08:00
parent 5557dd66f5
commit 6b71ba9418
3 changed files with 63 additions and 11 deletions

View file

@ -37,13 +37,15 @@
methods: {
handleClick () {
const $parent = this.$parent.$parent;
const hasChildren = this.$parent && this.$parent.$options.name === 'Dropdown';
if (this.disabled) {
this.$nextTick(() => {
$parent.visible = true;
});
} else if (hasChildren) {
this.$parent.$emit('on-haschild-click');
} else {
if ($parent.trigger === 'hover') {
$parent.visible = false;
if ($parent && $parent.$options.name === 'Dropdown') {
$parent.$emit('on-hover-click');
}
}

View file

@ -70,6 +70,14 @@
return false;
}
this.visible = false;
},
hasParent () {
const $parent = this.$parent.$parent;
if ($parent && $parent.$options.name === 'Dropdown') {
return $parent;
} else {
return false;
}
}
},
watch: {
@ -83,17 +91,22 @@
},
events: {
'on-click' (key) {
const $parent = this.$parent.$parent;
if ($parent && $parent.$options.name === 'Dropdown') {
$parent.$emit('on-click', key);
}
const $parent = this.hasParent();
if ($parent ) $parent.$emit('on-click', key)
},
'on-hover-click' () {
const $parent = this.$parent.$parent;
if ($parent && $parent.$options.name === 'Dropdown') {
$parent.visible = false;
$parent.$emit('on-hover-click');
}
this.$nextTick(() => {
this.visible = false;
});
const $parent = this.hasParent();
if ($parent) $parent.$emit('on-hover-click');
},
'on-haschild-click' () {
this.$nextTick(() => {
this.visible = true;
});
const $parent = this.hasParent();
if ($parent) $parent.$emit('on-haschild-click');
}
}
}