1、错误

创建一个vue实例,在data定义一些变量,如activityTime。

在methods里面用了axios发送请求。

在then的回调里使用this.activityTime

报错!

 

2、原因。then没有跟promise实例同步执行就会出现上述的错误。

axios的then(function(){

  console.dir(this)   //this->undefined

})

 

3、解决

可以用bind绑定this的指向当前vue的实例

axios的then(function(){

  console.dir(this)   //this->undefined

}.bind(this))

相关文章:

  • 2021-10-10
  • 2021-07-18
  • 2021-11-18
  • 2022-12-23
  • 2021-11-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-04-24
  • 2021-09-23
  • 2021-08-11
  • 2022-01-11
相关资源
相似解决方案