vue-Axios实现多个并行请求

该博客介绍了如何在Vue项目中利用Axios进行多个并行请求,主要聚焦于citys对象的处理和相关参考链接的分享。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  onSearch() {
          var that = this
          // 获取城市code
          const city = sessionStorage.getItem('departCity')
          const citys = window.cityMap.get(city) // 获取城市对象
          // 存储所有http请求
          const reqList = []
          // 存储后台响应每个请求后的返回结果
          const resList = []
          for (let i = 0; i < citys.children.length; i++) {
            var areaCode = citys.children[i].id
            const req = axios.get(process.env.BASE_API + '/api/rescure/sign/receive/rescureSignStatisticalList?areaCode=' + areaCode)
            reqList.push(req)
            resList.push(('post' + (i + 1)).replace(/[']+/g, ''))

         }
          return axios.all(reqList).then(axios.spread(function(...resList) {
            for (let i = 0; i < resList.length; i++) {
            // that.tableData全局变量-数组
              that.tableData.push(resList[i].data.result[0])
            }
            // return resList 
          }))
        },

citys对象

在这里插入图片描述

参考链接

添加链接描述 参考简书

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值