fix clone events
							parent
							
								
									2df0dec687
								
							
						
					
					
						commit
						93c3a70056
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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, | ||||
|         }, | ||||
|       }) | ||||
|     }, | ||||
|  |  | |||
|  | @ -1,6 +0,0 @@ | |||
| html { | ||||
|   overflow-y: auto !important; | ||||
| } | ||||
| body { | ||||
|   position: relative !important; | ||||
| } | ||||
|  | @ -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', | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 tangjinzhou
						tangjinzhou