错误:点击按钮以后想要视情况跳转页面,但是用this.props.history.push()的时候报错TypeError: Cannot read property ‘props’ of undefined

错误原因:没有给函数绑定this,函数内部引用this的时候无法解析出this,也就得不到this的属性props了。

解决方法:在组件的构造函数constructor中添加:
this.函数名=this.函数名.bind(this)
(注意函数名不能带括号)

React踩坑:TypeError Cannot read property props of undefined
React踩坑:TypeError Cannot read property props of undefined

相关文章:

  • 2021-05-18
  • 2021-07-01
  • 2021-09-21
  • 2021-12-09
  • 2021-09-14
  • 2021-06-23
猜你喜欢
  • 2022-12-23
  • 2021-12-24
  • 2021-04-02
  • 2021-08-28
  • 2021-07-16
  • 2021-09-09
  • 2021-06-26
相关资源
相似解决方案