es7 async await 异步
Posted qiudongjie
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);
},
以上是关于es7 async await 异步的主要内容,如果未能解决你的问题,请参考以下文章