解决异步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)
}