vue前端開發(fā)中,使用axios請求后臺報錯楼镐,源碼如下:
axios.get(url)
.then(function (response) {
this.storm = response.data.result;
console.log(response.data)
})
.catch(function (error) {
console.log(error)
})
報錯為:TypeError: Cannot set property ‘ storm’ of undefined
axios請求后article 發(fā)生變化癞志,而我使用的是名字函數(shù),this 關(guān)鍵字是匿名函數(shù)框产,vue實例凄杯,改成箭頭函數(shù)就行,如下:
axios.get(url).then((response) => {
this.storm = response.data.result;
console.log(result);
})
.catch(function (error) {
console.log(error)
})