天天看點

【異步】異步處理async/await

  async的用法,它作為一個關鍵字放到函數前面,用于表示函數是一個異步函數,因為async就是異步的意思, 異步函數也就意味着該函數的執行不會阻塞後面代碼的執行。

async presentAlertPrompt(status: any, type: any, id: any, userId: any, idId: any, extendId1: any, extendId2: any) {
    const alert = await this.alertController.create({
      header: '請輸入拒絕理由',
      inputs: [
        {
          id: 'msg',
          name: 'msg',
          type: 'text',
          placeholder: '請輸入拒絕理由!'
        }
      ],
      buttons: [
        {
          text: '取消',
          role: 'cancel',
          handler: () => {
            console.log('Cancel clicked');
          }
        },
        {
          text: '确定',
          handler: data => {
            const rn = (data.msg).trim();
            if (rn === '') {
              super.showToast(this.toastCtrl, '拒絕理由不可以為空哦');
              return;
            }
            this.message = rn;
            this.changeStatus2(status, type, id, userId, idId, extendId1, extendId2, this.message);
          }
        }
      ]
    });
    await alert.present();
  }
           

拓展:

回調地獄 https://www.jianshu.com/p/39adf6ab8ad1