Multiple promises are executed at the same time, waiting for the last return value

Needed by the project, fortunately, I recalled that it was recorded in "JavaScript You Don't Know"

Promise.all:
Promise.all([x,x,x,x]) other promise operations represented by x, you can bring everything that is encapsulated by promise, such as Ajax. Note:
these promise parameters must return resolve and reject resolutions. Of course, if you use a third-party plug-in, it may have already encapsulated promise, so you don’t have to worry about it.

      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()
            }
          })
        })

Guess you like

Origin blog.csdn.net/weixin_43311271/article/details/103324237