用ES6写法,这里的props是获取不到的,需要在constructor里加入
// This binding is necessary to make `this` work in the callback this.handleClick = this.handleClick.bind(this);这句话来绑定自身的事件,才能获取到需要的props
在React使用ES6语法时,遇到在事件处理函数中无法访问props的情况。解决办法是在构造函数中通过`this.handleClick.bind(this)`来绑定事件处理函数,确保在回调中能正确获取props。
用ES6写法,这里的props是获取不到的,需要在constructor里加入
// This binding is necessary to make `this` work in the callback this.handleClick = this.handleClick.bind(this);这句话来绑定自身的事件,才能获取到需要的props
1235
1072
1094
1236

被折叠的 条评论
为什么被折叠?