原代码
created(){
function getPetTypes(){
return axios.get(url.getPetTypes)
}
function getProductTypes(){
return axios.get(url.getProductTypes)
}
axios.all([getPetTypes(),getProductTypes()])
.then(axios.spread(function(acct,perm){
console.log(acct.data)
this.petTypes = acct.data
console.log(perm)
}))
},
出现错误
在这里仍然是可以获得数据的,但是却不能将其赋值到外部变量。
解决:
这是由于this指向引起的,所以将function改成箭头函数即可
created(){
function getPetTypes(){
return axios.get(url.getPetTypes)
}
function getProductTypes(){
return axios.get(url.getProductTypes)
}
axios.all([getPetTypes(),getProductTypes()])
.then(axios.spread((acct)=>{
console.log(acct.data)
this.petTypes = acct.data
}))
},