今天爱分享给大家带来React 事件处理程序 this undefined 如何处理【方法总结】 ,希望能够帮助到大家。
React 中,事件处理程序中,默认情况下,this为 undefined ,如果使用 this ,可以使用如下方法
第一种:
绑定事件处理程序时,使用bind方法绑定this
如:
第二种:
construtor() 方法中,使用 bind 方法绑定 this
construtor () {
super();
this.addComment = this.addComment.bind(this)
}
第三种:
使用箭头函数,来定义事件处理程序
addComment = ()=>{
}
第四种:
原文链接:https://blog.itblood.com/963.html,转载请注明出处。

![文学无尽俱乐部v0.53汉化版 [欧美SLG/汉化/动态]](/wp-content/uploads/replace/2025/07/18/16e2e1cfcc37ff72335e92985e1f9847.webp)