element plus el-table 简单分页组件

分页组件定义

PaginationTable.vue

<template>
 <!-- 外部可以自定义列 -->
  <slot></slot>
  <el-pagination @change="props.handleChangePage" layout="prev, pager, next" :page-size=" props.data.size?? 10" :total="props.data.total?? 0" />
</template>

<script setup>


import { ref, watchEffect } from 'vue';
const props = defineProps({
  data: Object, // 分页参数
  handleChangePage: Function, // 页码点击处理函数
})

console.log({...props.data})
</script>

<style>

</style>

使用

role.vue

<template>
  <PageNationTable :handleChangePage="handleChangePage" :data="pageData">
     <!-- normal element table here -->
    <el-table :data="tableData" style="width: 100%;" height="100%">
    <el-table-column prop="id" label="id" width="120" />
    <el-table-column prop="roleName" label="角色名" width="120" />
    <el-table-column prop="roleDescription" label="描述" width="120" />
    <el-table-column prop="createTime" label="创建时间" width="200" />
    <el-table-column prop="updateTime" label="更新时间" width="200" />
    </el-table>
  </PageNationTable>
</template>

<script setup>
import PageNationTable from '../components/PageNationTable.vue';
import { reactive, ref } from 'vue'
import http from '../../http'
// fetch data -> get data and page info -> ref([])
//                      ->  show in table 
//                      -> pass to this compoment to show pagination
const tableData = ref([
])

// 定义分页参数
const pageData = reactive({
  page: 1,
  size: 2,
  total: 0
});
// 页码点击事件
function handleChangePage(e) {
  pageData.page = e
  fetchRoles()
}
// 页面数据查询接口
fetchRoles()

async function fetchRoles() {
  const res = await http.get('/api/role/list?' +  new URLSearchParams({pageNum: pageData.page, pageSize: pageData.size}))
  const { list, page, total } = res.data;
  pageData.page = page
  pageData.total = total
  tableData.value = list
}

</script>

<style>

</style>
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值