Original code
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)
}))
},
An error occurs. The
data is still available here, but it cannot be assigned to an external variable.
Solution:
This is caused by the this point, so change the function to an arrow 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
}))
},