【发布时间】:2018-04-20 17:46:01
【问题描述】:
我在我的反应组件中调用一个函数
<button onClick={this.createComment}>Submit Comment</button>
在我的 createComment 函数中,“this”由于某种原因未定义
createComment(event) {
console.log('inside createComment')
console.log('event', event)
console.log('this', this)
event.preventDefault()
}
我需要在 createComment 函数中调用 this.setState。
如何让this 成为组件的 this??
【问题讨论】:
标签: reactjs