axios 执行多个并发请求

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  </head>
  <body>
    axios
    <script type="text/javascript">
    function getQuestionList() {
      var params = new URLSearchParams();
      params.append('pageNo',1)
      params.append('pageSize',10)
      return axios.post('/api/question/list',params);
    }
    function getCategoryList() {
      return axios.get('/api/category/getAll');
    }

    axios.all([getQuestionList(), getCategoryList()])
  .then(axios.spread(function (acct, perms) {
    // 两个请求现在都执行完成
    console.log(acct,perms);
  }));

    </script>
  </body>
</html>

  

posted @ 2018-08-21 01:47  renyangli  阅读(7571)  评论(0编辑  收藏  举报