Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaraBABA's avatar

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

0 likes
2 replies
piljac1's avatar
piljac1
Best Answer
Level 28

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).

1 like
LaraBABA's avatar

@piljac1 But I believe that each promise but end with a return statement if I am correct.

Please or to participate in this conversation.