我有一个数组,它包含一个具有两个值的对象,如下所示:
[
 {
  brand: app1,  
  url: https://myhost.com/api
 },
 {
  brand: app2,  
  url: https://otherapi.com/api
 }
]我使用axios.all对所有urls发出get请求,并使用一个映射进行迭代,如下所示:
const getData= axios.all(stuffData.map((item) => axios.get(item.url)))
.then(res => console.log(res.data)问题是,当我创建映射以插入所有的axios请求时,如何传递数组中的第二个param?我还需要通过关键的“品牌”。
谢谢
发布于 2022-04-23 15:26:17
用这个:
Promise.all(stuffData.map(async (item) => ({ 
  data: await axios.get(item.url).data, 
  brand: item.brand
}))).then((data) => {
   data.forEach(item=> console.log(item))
})https://stackoverflow.com/questions/71980827
复制相似问题