react阻止冒泡失败的解决方法:
在React中e.stopPropagation()无法阻止事件冒泡,可以使用 e.nativeEvent.stopImmediatePropagation() 完美解决。
class Test extends React.Component{ componentDidMount(){ document.onclick=this.two; } one(e){ e.nativeEvent.stopImmediatePropagation(); alert('one') } two(){ <span style="color:transparent">来源gaodai#ma#com搞*!代#%^码网</span> alert('two') } render(){ return(<div style={{height:200,width:200,backgroundColor:"#ccc"}} onClick={this.one}/>) } } ReactDOM.render( <Test/>, document.getElementById("test") );
更多react的相关知识,请查阅 搞代码网 !!
以上就是react阻止冒泡失败怎么解决?的详细内容,更多请关注gaodaima搞代码网其它相关文章!