vue managed on api asynchronous process is preferably

/ *
The async: Wait await asynchronous wait until after the next on a promise a pormise finished simultaneously resolve await further received parameter is

Syntax var fn = asnyc function () {}

is preferably used together with the promise async
* /

// var fn = async function () {} // this function is asynchronous


var fn1 = function(){
return new Promise((resolve)=>{
setTimeout(()=>{
console.log(111);
var obj = {name:1}
resolve(obj);
},2000)
})
}

var fn2 = function(){
return new Promise((resolve)=>{
setTimeout(()=>{
console.log(222)
resolve();
},1000)
})
}

var fn3 = function(){
return new Promise((resolve)=>{
setTimeout(()=>{
console.log(333)
resolve();
},500)
})
}

 


// var p = new Promise(resolve=>{
// setTimeout(()=>{
// console.log(0000)
// resolve();
// },3000)
// })

// p.then(()=>{
// return fn1();
// })
// .then(()=>{
// return fn2();
// })
// .then(()=>{
// fn3();
// })

 


// var test = async ()=>{
// await fn1();
// await fn2();
// await fn3();
// }
// test();


var test = async ()=>{
let data = await fn1();
console.log(data);
}
test();

Guess you like

Origin www.cnblogs.com/PeiGaGa/p/11032692.html