• 同时发送多个请求

      Axios.all([request1, request2, request3])
          .then(
            Axios.spread((res1, res2, res3) => {
              console.log('全部加载完成')
            })
          )
          .catch(err => {
            console.log(err.response)
          });
    

    Axios.spread中的函数,请求全部完成后会调用,并且请求数据会一一对应参数。

    发送的请求数不确定时

    使用map结合Axios.all

      Axios.all(arr.map(function (data)=>{
      	return this.axios.post(....)
      }))
          .then(
            Axios.spread((...a) => {
              console.log('全部加载完成')
            })
          )
          .catch(err => {
            console.log(err.response)
          });
    

arr是会灵活变化的数组,根据map方法返回多个promise。

相关文章:

  • 2022-12-23
  • 2021-05-22
  • 2021-10-20
  • 2022-12-23
  • 2021-05-26
  • 2021-10-22
  • 2022-12-23
猜你喜欢
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2021-06-02
相关资源
相似解决方案