首页 > 移动平台 > 详细

vue-axios发送并发请求

时间:2021-04-11 21:28:10      阅读:36      评论:0      收藏:0      [点我收藏+]

  axios发送并发请求,也就是同时发送多个请求,当多个请求响应完毕,再统一拿到全部的数据进行处理。axios提供了此API让我们做到。

axios.all([axios({
  url: ‘http://httpbin.org/‘,
  method: ‘get‘
}),axios({
  url: ‘http://httpbin.org/‘,
  method: ‘get‘
})]).then(results => {
  console.log(results[0])
  console.log(results[1])
})

  results是一个数组,数组元素是封装着各个请求的响应结果。还有一种写法,如下:

axios.all([axios({
  url: ‘http://httpbin.org/‘,
  method: ‘get‘
}),axios({
  url: ‘http://httpbin.org/‘,
  method: ‘get‘
})]).then(axios.spread((res1,res2) => {
  console.log(res1)
  console.log(res2)
}))

 

vue-axios发送并发请求

原文:https://www.cnblogs.com/ibcdwx/p/14644196.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!