隠されたポップアップ層の空の部分をクリックして反応し、反応の障害をバブリングからのイベントを停止します

使用e.nativeEvent.stopImmediatePropagationは()イベントのバブリングを停止するように反応します

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
公開された22元の記事 ウォンの賞賛6 ビュー10000 +

おすすめ

転載: blog.csdn.net/qq_39024012/article/details/101060055