【问题标题】:Uncaught Error, object is not a function for this.state未捕获的错误,对象不是 this.state 的函数
【发布时间】:2022-11-12 08:28:53
【问题描述】:

我在this.state 收到错误消息:

constructor () {
  super()
  this.state = {
    resultText: ""
  }
  this.buttonPressed = this.buttonPressed.bind(this)
}

buttonPressed(input)
{
  console.log(input)

  if (input == '='){
    return this.calculateResult()
  }

  this.setState= ({
    resultText : this.state.resultText+input
  })
}

【问题讨论】:

  • 你得到了什么错误?

标签: javascript node.js react-native


【解决方案1】:

这是语法错误,只需更改:

this.setState= ({
  resultText : this.state.resultText+input
})

this.setState({
  resultText : this.state.resultText+input
})

【讨论】:

    猜你喜欢
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多