React click on an empty part of the hidden pop-up layer; React to stop the event from bubbling failure

Use e.nativeEvent.stopImmediatePropagation () react to stop the event bubbling

import React,{Component} from 'react';

class Text extends Component {

    componentDidMount(){
        document.onclick=()=>{
            console.log('body')
        };
    }

    click=(e)=>{
        e.nativeEvent.stopImmediatePropagation();
        console.log('点击')
    }

    render(){
        return (
            <div>
                <a onClick={(e)=>{this.click(e)}}>点击</a>
            </div>
        )
    }
}
export default Text
Published 22 original articles · won praise 6 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_39024012/article/details/101060055