
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(){
alert('two')
}
render(){
return(<div style={{height:200,width:200,backgroundColor:"#ccc"}} onClick={this.one}/>)
}
}
ReactDOM.render(
<Test/>,
document.getElementById("test")
);更多web前端开发知识,请查阅 HTML中文网 !!
以上就是react阻止冒泡失败怎么解决?的详细内容,更多请关注易知道|edz.cc其它相关文章!














