es7 async await 异步
created 里面
let _this = this;
async function asyncAwaitFn1() {
return await new Promise((resolve, reject) => {
_this.a(resolve);
})
}
async function asyncAwaitFn2() {
return await new Promise((resolve, reject) => {
_this.b(resolve);
})
}
const serialFn = async () => { //串行执行
console.time('serialFn')
await asyncAwaitFn1();
await asyncAwaitFn2();
console.timeEnd('serialFn')
}
serialFn();
-----------------------------------------------------------------------------------------------------------------------------
methods
a(resolve){
setTimeout(() => {
console.log(1)
if(resolve){
resolve();
}
}, 3000);
},
b(resolve){
setTimeout(() => {
console.log(2)
if(resolve){
resolve();
}
}, 1000);
},