当前位置: 代码迷 >> 综合 >> 关于在小程序中this.setData报错 Cannot read property 'setData' of undefined
  详细解决方案

关于在小程序中this.setData报错 Cannot read property 'setData' of undefined

热度:45   发布时间:2023-11-07 02:38:22.0
success: function(res)  {this.setData({selfintegral: res.data.integral,selfthrowtimes: res.data.throw_times})}

这时候会报错 Cannot read property ‘setData’ of undefined

我们只需要吧function换成箭头函数就可以

success: (res) => {this.setData({selfintegral: res.data.integral,selfthrowtimes: res.data.throw_times})}

或者 let that = this

  相关解决方案