您的当前位置:首页正文

Promise.all() 但凡遇到reject就停止其他请求的

来源:花图问答

解决核心思路,增加map

Promise.all([p1, p2].map(p => p.catch(e => e)))
Promise.all([p1, p2].map(p => p.catch(e => e)))
          .then(results => {
              let companyResult = results[0]
              let securityQuestionsResult = results[1]
              if(!(companyResult instanceof Error)){
                 = 
                this.model.postalCode = companyResult.data.postCode
              }
              if(!(securityQuestionsResult instanceof Error)){
                this.model.securityQuestionArr = securityQuestionsResult.data
              }
          })
          .catch(e => {
            this.$parent.loading = false
          })
          .finally(() => {
            this.$parent.loading = false
          })