以同一页面请求完所有接口后再结束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);
    })
},

 

Logo

前往低代码交流专区

更多推荐