vue_等多个请求执行完再执行下一个方法(Promise.all用法)
以同一页面请求完所有接口后再结束loading为例:function1() {return new Promise((resolve, reject) => {request1(requestParams).then((res) => {//接口1xxxresolve(res);}).catch(e =>{reject(e)})});},..
·
以同一页面请求完所有接口后再结束loading为例:
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);
})
},
更多推荐
已为社区贡献2条内容
所有评论(0)