複数の Promise が同時に実行され、最後の戻り値を待ちます。

プロジェクトに必要だったので、幸運なことに、それが「あなたの知らない JavaScript」に収録されていることを思い出しました。

Promise.all:
Promise.all([x,x,x,x]) x で表される他の Promise 操作、Ajax など、Promise でカプセル化されているものはすべて取り込むことができます。注: これらの Promise パラメータは、解決と拒否の解決を返す必要があります。もちろん、サードパーティのプラグインを使用している場合は、既にカプセル化された Promise がある可能性があるため、心配する必要はありません

      Promise.all([this.getTimes(), this.getTime(), this.getRate()])
        .then(res => {
    
    
          let cumm = JSON.parse(localStorage.getItem('customT'))
          if (cumm.type == 2) {
    
    
            this.isBtn = true;
            this.setSj(cumm.data)
          } else {
    
    
            this.isBtn = false;
          }
        }).catch(error => {
    
    
          alert('获取数据失败')
        })
        return new Promise((resolve, reject) => {
    
    
          var that = this;
          $.ajax({
    
    
            url: ipurl + '',
            type: 'post',
            dataType: "json",
            success: function (res) {
    
    
              resolve()
            },
            error: function () {
    
    
              reject()
            }
          })
        })

おすすめ

転載: blog.csdn.net/weixin_43311271/article/details/103324237