I am using vue js and axios.
Here is what I am trying to do:
My "outlines" array gets usually between 3 to 9 entries. I would like to run an axios request(runSecondFunction()) on each entry, but only run 1 request at a time(wait for each record to be fetched before initiating another next request, and not all at once. If one of the requests fails, have an error message. Right now as it is, it works but some of the request finish before the others and my index position is wrong in the response.
method1(){
for (const [index, value] of this.splitOutlines.entries()) {
this.runSecondFunction(value, index);
}
}
runSecondFunction(value, index){
let formData = {
title: this.blog.value,
subheading: value
};
axios.post('/dashboard/paragraphs', formData).then((response) => {
this.articles.push({
index: index,
subheading: response.data.subheading,
paragraph: response.data.data.ideas[0],
});
}).catch(error => {
//
});
}
Any idea how to do this please?
Thanks