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)

}

 

posted @ 2020-09-08 17:14  jeff_zhu  阅读(750)  评论(0编辑  收藏  举报