【異步】異步處理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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章