Answer the question
In order to leave comments, you need to log in
Vue+js how to make axios execute one by one?
There is a function that sends axios:
getSchedules(locationId, gameModeId, selectedHeadsets, day) {
let param = 'locationId=' + locationId + '&gameModeId=' + gameModeId + '&headsets=' + selectedHeadsets
if (day)
param += '&day=' + day;
return axios({
method: 'get',
url: 'schedules?' + param
}).then((response) => {
if(this.curDateEvent){
this.changeMobileDay(this.curDateEvent);
}
}).catch((error) => {
});
}
Answer the question
In order to leave comments, you need to log in
If this is exactly what you want, then you can make yourself a queue, conditionally like this:
class AsyncQueue {
constructor(result) {
this.queue = [];
this.result = result;
}
isStreaming = false;
add(promise) {
this.queue.push(promise);
if(!this.isStreaming)
this.stream();
}
async stream() {
this.isStreaming = true;
for await (const result of this.queue) {
this.result(result);
}
this.queue.length = 0;
this.isStreaming = false;
}
}
data() {
const schedulesQueue = new AsyncQueue(this.showLoadedSchedules);
return {
schedulesQueue,
// ...
}
},
methods: {
showLoadedSchedules(response) {
if(this.curDateEvent) {
this.changeMobileDay(this.curDateEvent);
}
// ...
},
addSchedulesToQueue(locationId, gameModeId, selectedHeadsets, day) {
let param = 'locationId=' + locationId + '&gameModeId=' + gameModeId + '&headsets=' + selectedHeadsets
if (day)
param += '&day=' + day;
return this.schedulesQueue.add(
axios({
method: 'get',
url: 'schedules?' + param
}).catch((error) => {})
);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question