2016-12-03 23:46:25 +08:00
|
|
|
<template>
|
|
|
|
<li :class="classes" @click="handleClick"><slot></slot></li>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
const prefixCls = 'ivu-dropdown-item';
|
2018-03-28 22:47:10 +08:00
|
|
|
import { findComponentUpward } from '../../utils/assist';
|
2016-12-03 23:46:25 +08:00
|
|
|
export default {
|
2017-03-03 17:46:09 +08:00
|
|
|
name: 'DropdownItem',
|
2016-12-03 23:46:25 +08:00
|
|
|
props: {
|
2017-03-03 17:46:09 +08:00
|
|
|
name: {
|
2016-12-03 23:46:25 +08:00
|
|
|
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
|
|
|
];
|
2016-12-03 23:46:25 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleClick () {
|
2018-03-28 22:47:10 +08:00
|
|
|
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
|
|
|
|
2016-12-03 23:46:25 +08:00
|
|
|
if (this.disabled) {
|
|
|
|
this.$nextTick(() => {
|
2017-03-03 18:08:10 +08:00
|
|
|
$parent.currentVisible = true;
|
2016-12-03 23:46:25 +08:00
|
|
|
});
|
2016-12-04 14:33:06 +08:00
|
|
|
} else if (hasChildren) {
|
|
|
|
this.$parent.$emit('on-haschild-click');
|
2016-12-03 23:46:25 +08:00
|
|
|
} 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
|
|
|
}
|
2016-12-03 23:46:25 +08:00
|
|
|
}
|
2017-03-03 17:46:09 +08:00
|
|
|
$parent.$emit('on-click', this.name);
|
2016-12-03 23:46:25 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
|
|
|
</script>
|