Same thing (except that the second one has a then that will be called when all promises are resolved and not the first one). Otherwise, same thing. As for which is the best, I would say it depends on the nature of the endpoints. If they're dynamic (depending on some conditions, some URLs are called and others are not), first snippet is more appropriate. If they're nor dynamic, the second snippet is more programmer friendly (assuming you would give meaningful names to your methods).
Jul 27, 2022
2
Level 10
Difference between 2 axios calls in a mounted hook in Vue
Hello,
Would anyone knows the difference between these 2 axios calls in a mounted hook(Vue). First version
let endpoints = [
'https://api.github.com/users/ejirocodes',
'https://api.github.com/users/ejirocodes/repos',
'https://api.github.com/users/ejirocodes/followers',
'https://api.github.com/users/ejirocodes/following'
];
axios.all(endpoints.map((endpoint) => axios.get(endpoint))).then(
(data) => console.log(data),
);
second version
axios.all([
this.method1(),
this.method2(),
this.method3(),
this.method4(),
]).then(axios.spread((...responses) => {
})).catch((errors) => {
console.log("Dropdowns and Listing Details not all loaded!");
});
Are they not both calling each method concurrently?
Any cases where you should use one compared to the other please?
Thank
Level 28
1 like
Please or to participate in this conversation.