Home  >  Q&A  >  body text

How does axios synchronize requests - Stack Overflow

I have many requests, and they will all be sent out at once, and then all of them will be in a waiting state, causing the code to be asynchronous. How can I change the axios request to be synchronous, that is, after one request is completed, the next request is sent?

What I need is that after all these requests are completed, a list will be returned to me, which contains all the results
Note: The number of requests is uncertain, and the parameters are also uncertain. Now it is requested by a for loop.

给我你的怀抱给我你的怀抱2672 days ago2184

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-06-26 10:55:40

    Using axios.all can trigger the callback only when multiple ajax requests are completed. Reference: https://www.npmjs.com/package...

    axios.all([getUserAccount(), getUserPermissions()])
      .then(axios.spread(function (acct, perms) {
        // Both requests are now complete 
      }));

    reply
    0
  • 某草草

    某草草2017-06-26 10:55:40

    axios does not support synchronous requests at all

    reply
    0
  • Cancelreply