infinite-scroll.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <script setup lang="ts">
  2. import { ref } from "vue";
  3. import { default as vElTableInfiniteScroll } from "el-table-infinite-scroll";
  4. defineOptions({
  5. name: "InfiniteScroll"
  6. });
  7. const dataTemplate = new Array(10).fill({
  8. date: "2022-08-24",
  9. name: "RealityBoy",
  10. age: "18"
  11. });
  12. const data = ref([]);
  13. const page = ref(0);
  14. const total = ref(10);
  15. const isBottom = ref(false);
  16. const load = () => {
  17. if (isBottom.value) return;
  18. page.value++;
  19. if (page.value <= total.value) {
  20. data.value = data.value.concat(dataTemplate);
  21. }
  22. if (page.value === total.value) {
  23. isBottom.value = true;
  24. }
  25. };
  26. </script>
  27. <template>
  28. <el-card shadow="never">
  29. <template #header>
  30. <div class="font-medium">
  31. <el-link
  32. href="https://github.com/yujinpan/el-table-infinite-scroll"
  33. target="_blank"
  34. style="margin: 0 5px 4px 0; font-size: 16px"
  35. >
  36. 表格无限滚动
  37. </el-link>
  38. </div>
  39. <el-link
  40. class="mt-2"
  41. href="https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/able/infinite-scroll.vue"
  42. target="_blank"
  43. >
  44. 代码位置 src/views/able/infinite-scroll.vue
  45. </el-link>
  46. </template>
  47. <div class="mb-2">
  48. {{ isBottom ? "已加载全部页" : `加载到第 ${page} 页` }}
  49. </div>
  50. <el-table
  51. v-el-table-infinite-scroll="load"
  52. border
  53. height="435px"
  54. :data="data"
  55. :infinite-scroll-disabled="isBottom"
  56. >
  57. <el-table-column width="80" type="index" label="序号" />
  58. <el-table-column prop="date" label="日期" />
  59. <el-table-column prop="name" label="名称" />
  60. <el-table-column prop="age" label="年龄" />
  61. </el-table>
  62. </el-card>
  63. </template>