Elementui-plus 实现滚动到底部分页刷新

1.在这里面用了卡片来实现el-card滚动加载

    <div style="height: calc(100% - 280px);" class="el-main" v-loading="loading"
         element-loading-background="rgba(0, 0, 0, 0.3)" element-loading-text="Loading..." @scroll="handleScroll">
      <el-card class="box-card card-margin" v-for="item in itemList" :key="item.uavId"
               @click="chooseAirline(item)"
               :class="{'origin-card-active': selectSign == true && item.id == this.form.airlineId}">
}

 直接抓住重点,通过@scroll="handleScroll"来实现滚动分页加载数据。

2.

    handleScroll(event) {
      const {target} = event;
      const threshold = 200; // 距离底部100px时开始加载
      if (!this.loading && !this.pageTotal && target.scrollHeight - target.scrollTop <= target.clientHeight + threshold) {
        setTimeout(() => {
          this.loadMoreData();
        }, 500); // 设置1秒的延迟
      }
    },

你可以随机自定义在距离底部多久去加载数据。

3.

    loadMoreData() {
      if (this.loading) return;
      this.loading = true;
      this.queryParams.pageNum += 1; // 只有在成功加载了完整页数据后才递增页码

      let fromData = {
        pageSize: this.queryParams.pageSize,
        pageNum: this.queryParams.pageNum,
        airlineName: this.queryParams.taskName,
        startTime: this.queryParams.taskTime && this.queryParams.taskTime.length > 0 ? this.queryParams.taskTime[0] : '',
        endTime: this.queryParams.taskTime && this.queryParams.taskTime.length > 1 ? this.queryParams.taskTime[1] : '',
        uavName: this.queryParams.uavName,
        airlineTypes: this.queryParams.airlineType.join(',')
      };

      getLineList_c(fromData).then(res => {
        if (res.code === 200) {
          console.log("分页查询后的回调为", res)
          this.itemList = [...this.itemList, ...res.rows];
          console.log("this.itemList数组为", this.itemList)
          if (this.itemList.length == res.total) {
            this.pageTotal = true;
          }
        }
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
    },

将每一行多添加的代码重新添加到数组中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值