需求,两个异步请求,第二个请求参数为第一个请求返回值

将第一个请求封装为async函数

async function fn1(){

  axios.get().then(()=>{

    return '123'

  })

}

fn1().then((result)=>{

  axios.get().then(()=>{

    return '456'

  })

})

第二种

function getList(){

  return new Promise( function( resolve,reject){

    axios.get().then(()=>{

      resolve(123)

    })

  })

}

async function fn3(){

  let first = await getList();

  let second = await getList();

  let third = await getList();

  console.log(first,second,third)

}

 

相关文章:

  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
猜你喜欢
  • 2018-05-31
  • 2022-12-23
  • 2021-09-29
  • 2021-08-03
  • 2021-05-21
  • 2022-03-09
相关资源
相似解决方案