promise與await的用法


 1 save1(){
 2     return new Promise((resolve, reject)=> {
 3         console.log('ajax1')
 4     }) 
 5 }
 6 
 7 save2(){
 8     return new Promise((resolve, reject)=> {
 9         console.log('ajax2')
10         resolve(true)
11     })
12 }
13 
14 同時發送兩個ajax請求:
15 async saveAll() {
16     const flag1 = await this.save1()
17     const flag2 = await this.save2()
18     if (flag1 && flag2) {
19         console.log('allSuccess')
20         console.log('nextAjax')
21     }
22 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM