您的位置:首页 > 其它

Uncaught (in promise) TypeError:的错误

2017-05-19 11:02 344 查看
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))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐