0👍
✅
Try this:
getAnträgeByBenutzerID(){
this.test = [];
const promises = [];
this.benutzerIDs.forEach(id => {
promises.push(axios.get(server.baseURL + "/urlaubsantrag/benutzer/" + id))
})
axios
.all(promises)
.then(res =>
//res is an array of raw data
this.test = res.map(item => item.data);
)
}
0👍
You’ll need to use Promise.all
and Array.prototype.map
:
getAnträgeByBenutzerID(){
return Promise.all(this.benutzerIDs.map((id) =>
axios.get(server.baseURL + "/urlaubsantrag/benutzer/" + id)])));
}
The map callback creates an array of promises which are then collectively returned once they are all resolved.
Source:stackexchange.com