多次发同一个请求,判断多次请求什么时候结束。

有时候,我们需要加一些loading效果。在请求开始时触发loading 结束时关闭。一次请求,就在请求之前开启,请求成功之后关闭。

多次发同一个请求呢

vue环境下,可以在data中设置两个值

 data() {
    return {
      count: 0, 
      total: 10, //发请求的总数,对象或者数组的话可以使用对应的length
      loading: false,
    };
  },

在发请求之前把loading变为true,在每次发请求成功之后,count+1

this.loading = true
axios.post(,).then((res)=>{
    if(this.count < this.total){
        this.count += 1
    }
})

然后判断 count 和 total相等时 全部请求发送结束啦 把loading关了就行啦

if(this.count === this.total){
 this.loading = false
}

上一篇:Pycharm 高效编码技巧--模块自动导入


下一篇:解决 Pycharm 无法添加远程 Python 解释器:IndexOutOfBoundsException: Index 11 out of bounds for length 11