2016-11-09 57 views
0

子这里是我的JS斌演示:不能stopPropagation时呈现componentDidMount()

https://jsbin.com/baxipufozo/edit?html,js,output

我渲染DragDropChildDragDropParent componentDidMount

但是当我拖着孩子,家长触发dragstart呢!

同样的问题click事件

我试图e.stopPropagation()e.nativeEvent.stopPropagation()e.nativeEvent.stopImmediatePropagation()但他们都没有用

所以我不能stopPropagation时componentDidMount()渲染子,但我必须使孩子在didMount。

回答

0

好,可以防止父拖曳检测用一个简单的条件:

if(e.target.id === 'parent') { 
     console.log('parent'); 
     e.dataTransfer.setData('Text','parent') 
} 

但是你为什么不能使孩子正常,其母公司内部渲染方法?

+0

因为我正在重建一个旧项目.... – ReactNewbee