HTML
<template> <el-table :data="tableData.slice((page - 1) * limit, page * limit)" style="width: 100%"> <el-table-column prop="date" label="Date" width="180" /> <el-table-column prop="name" label="Name" width="180" /> <el-table-column prop="address" label="Address" /> </el-table> <!-- 分页 --> <el-pagination :current-page="page" small background layout="prev, pager, next" :total="total" class="mt-4" :page-size="limit" @size-change="handleSizeChange" @current-change="handleCurrentChange" /> </template>
JS
<script setup> // 分页 const limit = ref(3); // 每页数据 const page = ref(1); // 默认页数 const total = ref(0); // 总的数据 const tableData = [ { date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, ]; total.value = tableData.length; // 分页 const handleSizeChange = (val) => { limit.value = val; }; const handleCurrentChange = (val) => { page.value = val; }; </script>