I am currently utilizing vue js and axios for my project.
Here is the challenge I am facing:
Typically, my "outlines" array contains anywhere from 3 to 9 entries. I want to send an axios request (runSecondFunction()) for each entry, but execute only one request at a time (waiting for each record to be fetched before starting the next request, instead of all at once). In case any of the requests fail, display an error message. While the current setup works, some requests finish before others leading to incorrect index positions 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 => {
//
});
}
If you have any insights on how to achieve this, I would greatly appreciate it.
Thank you