请看下面两组代码
①
this.axios.post(url, data)
.then(function(result) {
var resData = result.data
console.log(resData)
if (resData.status === 1) {
} else {
}
})
.catch(function (error) {
console.log(error)
})
②
this.axios.post(url, data)
.then((result) => {
var resData = result.data
console.log(resData)
if (resData.status === 1) {
} else {
}
})
.catch(function (error) {
console.log(error)
})
这两组代码的差别在于:请求成功后的回调函数,一个使用匿名函数,一个使用箭头函数
匿名函数的指针指向->函数操作的本身
箭头函数的指针指向->组件
也就是说当你需要使用到组件中声明的变量或者函数,就需要使用箭头函数