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)

}

原文地址:https://www.cnblogs.com/jeff-zhu/p/13633780.html