刚刚入手小程序没多久 今天在写小程序时用到 this.setData时会报错

TypeError: Cannot read property 'setData' of undefined

 

 

 这个让我想起了 react this.setState({}) 一般在react中写点击事件的时候 都喜欢 这样写  onClick={this.bindClick.bind(this)}

OKOK 破案了 this 指向问题

TypeError: Cannot read property 'setData' of undefined

 

 解决了  但是这样写属实是麻烦  所以ES6 箭头函数走起吧

TypeError: Cannot read property 'setData' of undefined

 

相关文章: