axios 同時執行多個請求


http://chuansong.me/n/394228451820

同時執行多個請求

axios.all([

    axios.get('https://api.github.com/xxx/1'),

    axios.get('https://api.github.com/xxx/2')

  ])

  .then(axios.spread(function (userResp, reposResp) {

    // 上面兩個請求都完成后,才執行這個回調方法

    console.log('User', userResp.data);

    console.log('Repositories', reposResp.data);

  }));

 

當所有的請求都完成后,會收到一個數組,包含着響應對象,其中的順序和請求發送的順序相同,可以使用 axios.spread 分割成多個單獨的響應對象

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM