VUE @load事件触发多次分页

6 篇文章 0 订阅

前言

 <van-list v-model="loading" @load="initTodoList" :finished="isLoadFinished" :offset="getListMoreOffset">

写了个瀑布式分页,调用时多次,预期是两次,而且第二次开始,请求参数一致
在这里插入图片描述

原因

参考文章

非加载中loadingfalse,此时会根据列表滚动位置判断是否触发onload事件(列表内容不足一屏幕时,会直接触发)
加载中loadingtrue,表示正在发送异步请求,此时不会触发onload事件

解决

加载中应该设置为false,其次,达到最大条数时,isLoadFinished要设置为true

     this.loading = true;
            queryMyToDoListByTerm(this.queryParam).then(response => {
                if (response.code === 200) {
                    //自查分页
                    if (this.type == '2') {
                        //关闭
                        this.loading = false;
                        //追加数组
                        this.todoList = this.todoList.concat(response.data.list);
                        if ((this.queryParam.num*10) >= response.data.total) {
                            this.isLoadFinished = true;
                        } else {
                            this.queryParam.num++;
                        }
                        // this.listActive = true;
                        console.log("this.queryParam", this.isLoadFinished, this.queryParam.num,response.data.total )
                    } else {
                        this.todoList = response.data.list;
                        this.isLoadFinished = true;
                    }

                }
            });
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值