关于事件冒泡:useCapture 抛砖引玉,本屌有话说,为何跟我想象的不一样呢
1、注册鼠标按下事件
this.node.on(Node.EventType.MOUSE_DOWN, (event)=>{
console.log(“监听1___________”,event);
},this, true);
this.node.on(Node.EventType.MOUSE_DOWN, (event)=>{
console.log(“监听2___________”,event);
},this, false);
this.node.on(Node.EventType.MOUSE_DOWN, (event:EventMouse)=>{
console.log(“监听3___________”,event);
},this, true);
this.node.emit(Node.EventType.MOUSE_DOWN, “cocos牛逼”)
1)默认输出结果为:
监听2___________ cocos牛逼
2)鼠标按下输出结果为:
监听1___________ cocos牛逼
监听2___________ cocos牛逼
监听3___________ cocos牛逼
2、useCapture:全部为true
输出结果为:
监听1___________ cocos牛逼
监听2___________ cocos牛逼
监听3___________ cocos牛逼
于是乎我又按照官方的描述:
同时您可以将事件派发到父节点或者通过调用 stopPropagation 拦截它,无奈并未找到该方法。
至此让本来还略懂的冒泡机制 瞬间感觉彷徨了,还请大神不吝赐教!