iview/src/components/dropdown/dropdown-item.vue

59 lines
1.8 KiB
Vue
Raw Normal View History

<template>
<li :class="classes" @click="handleClick"><slot></slot></li>
</template>
<script>
const prefixCls = 'ivu-dropdown-item';
import { findComponentUpward } from '../../utils/assist';
export default {
2017-03-03 17:46:09 +08:00
name: 'DropdownItem',
props: {
2017-03-03 17:46:09 +08:00
name: {
type: [String, Number]
},
disabled: {
type: Boolean,
default: false
},
selected: {
type: Boolean,
default: false
},
divided: {
type: Boolean,
default: false
}
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-disabled`]: this.disabled,
[`${prefixCls}-selected`]: this.selected,
[`${prefixCls}-divided`]: this.divided
}
2016-12-25 22:49:42 +08:00
];
}
},
methods: {
handleClick () {
const $parent = findComponentUpward(this, 'Dropdown');
2016-12-04 14:33:06 +08:00
const hasChildren = this.$parent && this.$parent.$options.name === 'Dropdown';
2016-12-04 17:04:48 +08:00
if (this.disabled) {
this.$nextTick(() => {
2017-03-03 18:08:10 +08:00
$parent.currentVisible = true;
});
2016-12-04 14:33:06 +08:00
} else if (hasChildren) {
this.$parent.$emit('on-haschild-click');
} else {
2016-12-04 14:33:06 +08:00
if ($parent && $parent.$options.name === 'Dropdown') {
2016-12-04 13:52:51 +08:00
$parent.$emit('on-hover-click');
2016-12-04 00:38:57 +08:00
}
}
2017-03-03 17:46:09 +08:00
$parent.$emit('on-click', this.name);
}
}
2016-12-25 22:49:42 +08:00
};
</script>