Axios spread() with unknown number of callback parameters

后端 未结 1 1282
遇见更好的自我
遇见更好的自我 2021-02-01 05:31

I need to process an unknown number of AJAX requests (1 or more) with axios, and I am not sure how to handle the response. I want something along the lines of:

l         


        
相关标签:
1条回答
  • 2021-02-01 05:55

    You somewhere will need to make the actual requests. And then don't use spread but only then to receive the array of results:

    let urlArray = [] // unknown # of urls (1 or more)
    
    let promiseArray = urlArray.map(url => axios.get(url)); // or whatever
    axios.all(promiseArray)
    .then(function(results) {
      let temp = results.map(r => r.data);
      …
    });
    
    0 讨论(0)
提交回复
热议问题