• 欢迎光临~

Cannot read properties of undefined (reading 'setState')

开发技术 开发技术 2022-06-19 次浏览
Cannot read properties of undefined (reading 'setState')

 

this的指向不对,需要用bind绑定this

例如

constructor(props){
    super(props)
    
    this.state=store.getState()
    this.changeInputValue=this.changeInputValue.bind(this)//绑定
    store.subscribe(this.storeChange)//订阅
  }

 

程序员灯塔
转载请注明原文链接:Cannot read properties of undefined (reading 'setState')
喜欢 (0)