0👍
You also need to return your axios
call from your getItemNumber
function.
so the return 7;
will work as it’s not in the axios call it will return the value directly. but for returning the value from axios response.
The following code will return the value of the response when getItemNumber
is invoked
Try this.
getTotal(car){
console.log(car.id_car);
// return 7; //OK
return this.$axios.get(`/totalsales/${car.id_car}`)
.then((response) => {
if (response.data.success) {
return response.data.total[0].total; //?? HERE
} else { }
})
.catch(error => {
});
// -->
}
function axiosTest() {
return axios.get(url).then(response => {
// returning the data here allows the caller to get it through another .then(...)
return response.data
})
}
axiosTest().then(data => {
response.json({ message: 'Request received!', data })
})
Updated
Just create Mapping dict instead.
total_dict:{}
Methods
getTotal(car){
console.log(car.id_car);
axios.get(`https://api.github.com/users/barbier`)
.then((response) => {
this.$set(this.total_dict,car.id_car,response.data.id)
.bind(this)})
.catch(error => {
});
}
codepen – https://codepen.io/Pratik__007/pen/XWbezrJ?editors=1010
Source:stackexchange.com