axios中all方法的使用

handleAll(){
    let arr = [{id: 1}, {id: 2}, {id: 3}];
    
}
handleItem(pa){
    $api.postMethed(pa)
}

请问怎么在handleAll中根据arr的长度发送几个handleItem();并在所有的请求返回后进行判断?谢谢

阅读 4.9k
1 个回答
const axios = require('axios');

function handleItem(pa) {
  return $api.postMethed(pa);
}
function handleAll() {
  let arr = [{id: 1}, {id: 2}, {id: 3}];
  const requestArr = arr.map(i => {
    return handleItem(i)
  })
  return axios.all(requestArr);
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题