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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM