From 6b71ba941828309b9cd64692bf64a70d45187e06 Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Sun, 4 Dec 2016 14:33:06 +0800 Subject: [PATCH] update Dropdown --- src/components/dropdown/dropdown-item.vue | 6 ++++-- src/components/dropdown/dropdown.vue | 31 ++++++++++++++++++++++--------- test/routers/dropdown.vue | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/components/dropdown/dropdown-item.vue b/src/components/dropdown/dropdown-item.vue index 4441d84..a626cb6 100644 --- a/src/components/dropdown/dropdown-item.vue +++ b/src/components/dropdown/dropdown-item.vue @@ -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'); } } diff --git a/src/components/dropdown/dropdown.vue b/src/components/dropdown/dropdown.vue index 565f6af..ea23eb2 100644 --- a/src/components/dropdown/dropdown.vue +++ b/src/components/dropdown/dropdown.vue @@ -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'); } } } diff --git a/test/routers/dropdown.vue b/test/routers/dropdown.vue index d6b5ca9..07a17b0 100644 --- a/test/routers/dropdown.vue +++ b/test/routers/dropdown.vue @@ -1,6 +1,43 @@