解决异步promise async await

vue || js

promise

fun(){

  var this=that

  new promise((resolve,reject)=>{

    that.get().then(res=>{

      resolve(res)

    })

  }).then(res=>{

    console.log(res)

  })

}

function fun(){

  var this=that

  new promise((resolve,reject)=>{

    that.get().then(res=>{

      resolve(res)

    })

  }).then(res=>{

    console.log(res)

  })

}

fun()

 

vue

async await

使用一个async关键字函数,在这个函数内使用await关键字函数调用异步,同步事件

async 生命周期(){

  let res= await funs1()

  let res2= await funs2()

  console.log(res)

  console.log(res2)

}

async fun(){

  //await关键字调用事件

  let res=await get()

  let res2=await  post()

  console.log(res)

  console.log(res2)

}

 

posted @ 2021-09-28 23:24  谎渊  阅读(19)  评论(0)    收藏  举报