背景:表格是最为通用的展示方式,为了展示的统一性,以及分页组件的重用,这里写一个分页组件,供比较多或者较少数据2种表格进行分页展示。

分页组件:

<template>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="pageSizes"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="pageTotal"/>
</template>
<script>
export default {
props: {
tableBegin: {// 总数据
type: Array,
default () {
return []
}
},
pageSizes: {// 分页条数:数据较多设置为[25,50,100]
type: Array,
default () {
return [10, 20, 30]
}
}
},
data () {
return {
currentPage: 1,
pageSize: 10
}
},
computed: {
pageTotal () { // 分页前总条数
return this.tableBegin.length
}
},
watch: {
tableBegin: {
immediate: true,
handler (val) { // 加载数据
this.currentPage = 1
this.pageSize = this.pageSizes[0] || 10
const begin = (this.currentPage - 1) * this.pageSize
const end = this.currentPage * this.pageSize
const tableData = this.tableBegin.slice(begin, end)
this.$emit('table-pagination-change', tableData, this.currentPage, this.pageSize)
}
}
},
methods: {
// 每页条数
handleSizeChange (val) {
this.pageSize = val
const begin = (this.currentPage - 1) * this.pageSize
const end = this.currentPage * this.pageSize
const tableData = this.tableBegin.slice(begin, end)
this.$emit('table-pagination-change', tableData, this.currentPage, this.pageSize)
},
// 第几页
handleCurrentChange (val) {
this.currentPage = val
const begin = (this.currentPage - 1) * this.pageSize
const end = this.currentPage * this.pageSize
const tableData = this.tableBegin.slice(begin, end)
this.$emit('table-pagination-change', tableData, this.currentPage, this.pageSize)
}
}
}
</script>

使用示例:

import pagination from 'module-comp/tablePagination'

<pagination
:table-begin='tableBegin'
@table-pagination-change='getTableData'/>
// 展示数据
getTableData (data, currentPage, pageSize) {
this.tableData = data // 只需要赋值一次,其他情况均有传入的分页的数据回调处理
this.currentPage = currentPage
this.pageSize = pageSize
}
// 删除
deleteRow (index, row) {
this.tableBegin.splice((this.currentPage - 1) * this.pageSize + index, 1)
// this.tableData.splice(index, 1)
}

说明:

加入分页后表格的展示数据均由分页控制,即通过传入的tableBegin监听改变

最新文章

  1. c# 用户名 密码 访问 局域网共享
  2. Activemq消息持久化
  3. 明明已经执行Log.i,偏偏打不出日志
  4. android 提高进程优先级 拍照永不崩溃(闪退)
  5. OC中实例变量可见度、setter、getter方法和自定义初始化方法
  6. Linux搜狗输入法在有道云笔记上输入冗余
  7. ProgressBar 各种样式
  8. 避免SWF被内存提取工具提取的方法
  9. Linux Increase The Maximum Number Of Open Files / File Descriptors (FD)
  10. SpringMVC12拦截器
  11. IOS学习:常用第三方库(GDataXMLNode:xml解析库)
  12. 自己定义控件(2.2):SurfaceView和SurfaceHolder
  13. Spring中配置数据源的四种方式
  14. Python基础数据类型之字典
  15. sshpass笔记
  16. Struts 2 之文件上传
  17. HDU-problem-1002-人类史上最大最好的希望事件-矩阵快速幂
  18. 关于ehcache缓存中eternal及timeToLiveSeconds和timeToIdleSeconds的说明
  19. 认识LDAP协议
  20. elasticSearch新认知

热门文章

  1. HLSFFmpegBuilder适用于hls协议的构造器 没具体测试
  2. Python中random模块生成随机数详解
  3. C-LODOP回调多个返回值On_Return_Remain
  4. nodejs实现一个文件存储服务
  5. python 多线程模板简单实现
  6. Centos 更改MySQL5.7数据库目录位置
  7. mysql 基本操作及对用户操作
  8. mysql数据库表的查询
  9. Hive行列转换
  10. QPS、TPS、PV、UV、GMV、IP、RPS?