Dropdown will not trigger @on-click event when set disabled prop to DropdownItem

This commit is contained in:
梁灏 2019-09-04 16:14:23 +08:00
parent 2e03af9023
commit 53f950ab96
2 changed files with 11 additions and 10 deletions

View file

@ -1,14 +1,14 @@
<template> <template>
<div> <div>
<Dropdown trigger="hover"> <Dropdown trigger="hover" @on-click="handleClick">
<a href="javascript:void(0)"> <a href="javascript:void(0)">
下拉菜单 下拉菜单
<Icon type="ios-arrow-down"></Icon> <Icon type="ios-arrow-down"></Icon>
</a> </a>
<DropdownMenu slot="list"> <DropdownMenu slot="list">
<DropdownItem>驴打滚</DropdownItem> <DropdownItem name="1">驴打滚</DropdownItem>
<DropdownItem selected>炸酱面</DropdownItem> <DropdownItem selected name="2">炸酱面</DropdownItem>
<DropdownItem disabled>豆汁儿</DropdownItem> <DropdownItem disabled name="3">豆汁儿</DropdownItem>
<DropdownItem>冰糖葫芦</DropdownItem> <DropdownItem>冰糖葫芦</DropdownItem>
<DropdownItem divided>北京烤鸭</DropdownItem> <DropdownItem divided>北京烤鸭</DropdownItem>
</DropdownMenu> </DropdownMenu>
@ -43,6 +43,10 @@
</template> </template>
<script> <script>
export default { export default {
methods: {
handleClick (n) {
console.log(n);
}
}
} }
</script> </script>

View file

@ -37,14 +37,11 @@
}, },
methods: { methods: {
handleClick () { handleClick () {
if (this.disabled) return;
const $parent = findComponentUpward(this, 'Dropdown'); const $parent = findComponentUpward(this, 'Dropdown');
const hasChildren = this.$parent && this.$parent.$options.name === 'Dropdown'; const hasChildren = this.$parent && this.$parent.$options.name === 'Dropdown';
if (this.disabled) { if (hasChildren) {
this.$nextTick(() => {
$parent.currentVisible = true;
});
} else if (hasChildren) {
this.$parent.$emit('on-haschild-click'); this.$parent.$emit('on-haschild-click');
} else { } else {
if ($parent && $parent.$options.name === 'Dropdown') { if ($parent && $parent.$options.name === 'Dropdown') {