3. vue_等多个请求执行完再执行下一个方法(Promise.all用法)

getData1() { return new Promise((resolve, reject) => { request1(requestParams).then((res) => {//接口1 xxx resolve(res); }).catch(e =>{ reject(e) }) }); }, getData2() { return new Promise((resolve, reject) => { request2(requestParams).then((res) => {//接口2 xxx resolve(res); }).catch(e =>{ reject(e) }) }); }, getData() { this.addLoading()//开始loading Promise.all([ this.getData1(), this.getData2() ]).then(res => { console.log(res); setTimeout(() => { this.hideLoading()//延时结束loading }, 800); }) }

posted @ 2022-01-18 11:17  小蓉儿  阅读(1935)  评论(0编辑  收藏  举报