async函数项目中使用方法


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

将第一个请求封装为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)

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM