constructor(props){
        super(props)
        this.myRefs = React.createRef();
    }
    refFun(){
        const node = this.myRefs.current
        node.style.color = "red"
    }
    render() {
        return ( 
            <div>
                <button ref={this.myRefs} onClick={this.refFun.bind(this)}>refs点击按钮</button>
            </div>
        )
    }

 

posted on 2020-07-03 17:26  chenlw101  阅读(210)  评论(0编辑  收藏  举报