From 42776ba79c81c5a51d8143a1df9889b9d95859ba Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Mon, 5 Feb 2018 11:18:50 +0800 Subject: [PATCH] fix clone events --- components/_util/vnode.js | 19 +++++++++++++------ components/dropdown/src/Dropdown.vue | 23 ++++++++--------------- components/style/vue-antd.less | 6 ------ components/trigger/index.vue | 12 ++++-------- 4 files changed, 25 insertions(+), 35 deletions(-) delete mode 100644 components/style/vue-antd.less diff --git a/components/_util/vnode.js b/components/_util/vnode.js index 663aa7972..e36d6e822 100644 --- a/components/_util/vnode.js +++ b/components/_util/vnode.js @@ -1,19 +1,26 @@ import cloneDeep from 'lodash.clonedeep' export function cloneVNode (vnode, deep) { const componentOptions = vnode.componentOptions - // if (componentOptions && componentOptions.listeners) { - // componentOptions.listeners = cloneDeep(componentOptions.listeners) - // } + const data = vnode.data + + let listeners = {} + if (componentOptions && componentOptions.listeners) { + listeners = cloneDeep(componentOptions.listeners) + } + + let on = {} + if (data && data.on) { + on = cloneDeep(data.on) + } - // const data = vnode.data ? cloneDeep(vnode.data) : vnode.data const cloned = new vnode.constructor( vnode.tag, - vnode.data, + data ? { ...data, on } : data, vnode.children, vnode.text, vnode.elm, vnode.context, - componentOptions, + componentOptions ? { ...componentOptions, listeners } : componentOptions, vnode.asyncFactory ) cloned.ns = vnode.ns diff --git a/components/dropdown/src/Dropdown.vue b/components/dropdown/src/Dropdown.vue index e99d348e2..33ab717e9 100644 --- a/components/dropdown/src/Dropdown.vue +++ b/components/dropdown/src/Dropdown.vue @@ -4,7 +4,7 @@ import Trigger from '../../trigger' import placements from './placements' import { hasProp } from '../../_util/props-util' import BaseMixin from '../../_util/BaseMixin' -import { cloneElement, getEvents } from '../../_util/vnode' +import { cloneElement, getEvents, cloneVNode } from '../../_util/vnode' export default { mixins: [BaseMixin], @@ -68,21 +68,14 @@ export default { }, getMenuElement () { - const child = this.$slots.overlay[0] - const events = getEvents(child) - if (!events._ANT_DROPDOWN_EVENT_HACK) { - this.childOriginEvents = events - } - const { prefixCls } = this.$props - const extraOverlayProps = { - prefixCls: `${prefixCls}-menu`, - } - const overlay = this.$slots.overlay[0] - return cloneElement(overlay, { - props: extraOverlayProps, + const { onClick, prefixCls, $slots } = this + this.childOriginEvents = getEvents($slots.overlay[0]) + return cloneElement(cloneVNode($slots.overlay[0]), { + props: { + prefixCls: `${prefixCls}-menu`, + }, on: { - click: this.onClick, - _ANT_DROPDOWN_EVENT_HACK: () => {}, + click: onClick, }, }) }, diff --git a/components/style/vue-antd.less b/components/style/vue-antd.less deleted file mode 100644 index ffc69056d..000000000 --- a/components/style/vue-antd.less +++ /dev/null @@ -1,6 +0,0 @@ -html { - overflow-y: auto !important; -} -body { - position: relative !important; -} diff --git a/components/trigger/index.vue b/components/trigger/index.vue index 24023bdd1..691d5c127 100644 --- a/components/trigger/index.vue +++ b/components/trigger/index.vue @@ -9,7 +9,7 @@ import warning from '../_util/warning' import Popup from './Popup' import { getAlignFromPlacement, getPopupClassNameFromAlign, noop } from './utils' import BaseMixin from '../_util/BaseMixin' -import { cloneElement, filterEmpty, getEvents } from '../_util/vnode' +import { cloneElement, filterEmpty, getEvents, cloneVNode } from '../_util/vnode' function returnEmptyString () { return '' @@ -497,15 +497,11 @@ export default { if (children.length > 1) { warning(false, 'Trigger $slots.default.length > 1, just support only one default', true) } - const child = children[0] - const events = getEvents(child) - // 黑科技,vue暂未发现保留原事件的方法,使用_ANT_TRIGGER_EVENT_HACK来判断事件是否更新 - if (!events._ANT_TRIGGER_EVENT_HACK) { - this.childOriginEvents = events - } + const child = cloneVNode(children[0]) + this.childOriginEvents = getEvents(children[0]) const newChildProps = { props: {}, - on: { _ANT_TRIGGER_EVENT_HACK: () => {} }, + on: {}, key: 'trigger', }