我们在调用接口的时候,使用的是异步方式。很多时候我们想用接口返回的数据时,得不到想要的数据。因为这时接口还没有调用完。使用的异步方式,所以我们需要让接口进行同步请求。

所以我们需要再函数前面 加上 async ,在接口前面加上 await,也就是需要同步的地方加上 await 

async getList() {
      let res = 0;
      await listPatrol(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
        res = 1;
      });
      console.log(res);
    },

 

 

Logo

前往低代码交流专区

更多推荐