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

解决核心思路,增加map

Promise.all([p1, p2].map(p => p.catch(e => e)))

参考:
https://stackoverflow.com/questions/31424561/wait-until-all-es6-promises-complete-even-rejected-promises/36115549#36115549

https://davidwalsh.name/promises-results

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.companyType = companyResult.data.companyType
                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
          })

你可能感兴趣的:(Promise.all() 但凡遇到reject就停止其他请求的问题)