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
          })
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。