react绑定点击事件无效

不传参数时候 函数定义成箭头函数直接使用

render () {
        return (
            <div>
                <h4>请发表你的看法</h4>
                <div className ="flex">
                    <Add addItemFun={this.addItemFun}/>
                    <Lists commentList={this.state.commentList} deleItemFun ={this.deleItemFun} />
                </div>
            </div> 
        )
    }

传递参数的时候,函数仍然是定义成箭头函数

 render() {
        const {content,deleItemFun} = this.props;
        return (
            <div>
                <p>{content.userName}说:</p>
                <p>{content.comment}</p>
                <br/>
                <button onClick={()=>this.deleItem(content.id)}>删除</button>
            </div>
        )
    }

 

不停学习,热爱是源源不断的动力。
原文地址:https://www.cnblogs.com/ximenchuifa/p/14944663.html