promise.all()取多个数据

getLatestJob(context){
      const result1=api.getJobJsonFromShield(context)
        .then(response => {
          return response.json();
        });
      const result2=api.getJobJson(context)
        .then(response => {
          return response.json();
        });

      Promise.all([result1, result2])
        .then(([shieldData, nbuData])=>{
          context.commit('mergeList',{"shield":shieldData,"nbuData":nbuData})

        });
    }

两个result已经取回数据了 response.json()也是promise对象
所以进来之后是先依次执行result1 result2 然后再promise.all

Promise.all可以将多个Promise实例包装成一个新的Promise实例。同时,成功和失败的返回值是不同的,成功的时候返回的是一个结果数组,而失败的时候则返回最先被reject失败状态的值。

猜你喜欢

转载自blog.csdn.net/weixin_36869329/article/details/82841374