update Dropdown

update Dropdown
This commit is contained in:
梁灏 2016-12-04 13:35:09 +08:00
parent 79633f3c02
commit 745bcbc25e
3 changed files with 53 additions and 27 deletions

View file

@ -6,7 +6,7 @@
@mouseleave="handleMouseleave"
v-clickoutside="handleClose">
<div :class="[prefixCls-rel]" v-el:reference><slot></slot></div>
<Drop v-show="visible" :placement="placement" transition="slide-up"><slot name="list"></slot></Drop>
<Drop v-show="visible" :placement="placement" transition="slide-up" v-ref:drop><slot name="list"></slot></Drop>
</div>
</template>
<script>
@ -17,6 +17,7 @@
const prefixCls = 'ivu-dropdown';
export default {
name: 'Dropdown',
directives: { clickoutside },
components: { Drop },
props: {
@ -26,11 +27,11 @@
},
default: 'hover'
},
align: {
placement: {
validator (value) {
return oneOf(value, ['left', 'center', 'right']);
return oneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']);
},
default: 'center'
default: 'bottom'
}
},
data () {
@ -39,11 +40,6 @@
visible: false
}
},
computed: {
placement () {
return this.align === 'left' ? 'bottom-start' : this.align === 'center' ? 'bottom' : 'bottom-end';
}
},
methods: {
handleClick () {
if (this.trigger !== 'click') {
@ -79,9 +75,17 @@
watch: {
visible (val) {
if (val) {
this.$broadcast('on-update-popper');
this.$refs.drop.update();
} else {
this.$broadcast('on-destroy-popper');
this.$refs.drop.destroy();
}
}
},
events: {
'on-click' (key) {
const $parent = this.$parent.$parent;
if ($parent && $parent.$options.name === 'Dropdown') {
$parent.$emit('on-click', key);
}
}
}