赞
踩
下载插件
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>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。