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