Uncaught (in promise) TypeError:的错误

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))

posted @ 2017-05-19 11:02  leaf+  阅读(5948)  评论(0编辑  收藏  举报