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