(vue3)el-table滚到底部加载数据el-table-infinite-scroll

下载插件

npm install --save el-table-infinite-scroll

全局

import { createApp } from "vue";
import App from "./src/App.vue";

import ElTableInfiniteScroll from "el-table-infinite-scroll";

const app = createApp(App);

app.use(ElTableInfiniteScroll);
app.mount("#app");

局部

<template>
  <el-table v-el-table-infinite-scroll="load"></el-table>
</template>

<script setup>
import { default as vElTableInfiniteScroll } from "el-table-infinite-scroll";
</script>

el-table实现

<template>
  <p style="margin-bottom: 8px">
    <span>loaded page(total: {{ total }}): {{ page }}, </span>
    disabled:
    <el-switch v-model="disabled" :disabled="page >= total"></el-switch>
  </p>

  <el-table
    v-el-table-infinite-scroll="loadMore"
    :data="data"
    :infinite-scroll-disabled="disabled"
    height="200px"
  >
    <el-table-column type="index" />
       ...
  </el-table>
</template>

<script setup>
import { ref } from 'vue';

const dataTemplate = new Array(10).fill({
  date: '2009-01-01',
  name: 'Tom',
  age: '30',
});

const data = ref([]);
const disabled = ref(false);
const page = ref(0);
const total = ref(5);

const loadMore= () => {
  if (disabled.value) return;

  page.value++;
  if (page.value <= total.value) {
    data.value = data.value.concat(dataTemplate);
  }

  if (page.value === total.value) {
    disabled.value = true;
  }
};
</script>

<style lang="scss" scoped>
.el-table {
  :deep(table) {
    margin: 0;
  }
}
</style>

原文链接 vue3 | el-table-infinite-scroll

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值