thirdScriptError Cannot read property setData of undefined at api request success

  在微信小程序里面用this.setData({})设置data中的变量出现的问题,我出现问题的是一个request的请求,要把请求到的数据放到data中,这里看起来很正常,语法也没有错误,但是注意这里用的并不是箭头函数,所以函数内部的this指向的并不是函数外部环境的this,而是函数自身,所以没有办法将想要的数据存到data中而报错
thirdScriptError Cannot read property setData of undefined at api request success正确的做法:
thirdScriptError Cannot read property setData of undefined at api request success在request函数外面手动将一个变量设置为外部环境的this,然后在request内部使用该变量,使得指针可以成功指向外部环境的this

相关文章:

  • 2021-09-28
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-03
  • 2021-09-11
  • 2021-11-22
猜你喜欢
  • 2021-06-19
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2021-09-29
  • 2021-11-07
  • 2022-12-23
相关资源
相似解决方案