表格分页优化:

<template>
<el-pagination
small
background
@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: {
resetPageSize: {// 重置页面
type: Boolean,
default: false
},
dataTotal: {// 总条数
type: [String, Number],
default: 0
},
tableBegin: {// 总数据
type: Array,
default () {
return []
}
},
pageSizes: {// 分页条数:自定义[10,20,30]
type: Array,
default () {
return [15, 25, 50, 100]
}
}
},
data () {
return {
currentPage: 1,
pageSize: 15
}
},
computed: {
pageTotal () { // 分页前总条数:后台读取或直接计算传入数据
return this.dataTotal || this.tableBegin.length
}
},
watch: {
tableBegin: {
immediate: true,
handler () { // 加载数据:初始化、更新数据
this.resetSize()
this.updateData()
}
},
resetPageSize: {
immediate: false,
handler () { // 切换路由等:重置分页
this.resetSize()
}
}
},
methods: {
// 跳转到第几页
handleCurrentChange (val) {
this.currentPage = val
this.updateData()
},
// 设置分页条数
handleSizeChange (val) {
this.resetSize()
this.pageSize = val
this.updateData()
},
// 重置分页
resetSize(){
this.currentPage = 1
this.pageSize = this.pageSizes[0] || 15
},
// 更新数据
updateData(){
const begin = (this.currentPage - 1) * this.pageSize
const end = this.currentPage * this.pageSize
const tableData = this.tableBegin.slice(begin, end)
if (this.dataTotal) { // 后台请求:不返回数据
this.$emit('table-pagination-update', this.currentPage, this.pageSize)
} else {
this.$emit('table-pagination-change', tableData, this.currentPage, this.pageSize)
}
this.$emit('change', tableData, this.currentPage, this.pageSize)
}
}
}
</script>

如何使用:

    <!-- 页码 -->
<pagination
style="margin-top:10px"
:page-sizes="pageSizes"
:table-begin="tableBegin"
@table-pagination-change="getTablePagination"
/>
</div>
</template> <script>
import pagination from 'module-comp/tablePagination'
export default {
components: {
pagination
}, // 分页方法
getTablePagination (data, currentPage, pageSize) {
this.tableData = data
this.currentPage = currentPage
this.pageSize = pageSize
},

后台控制返回:

     <pagination
ref="pager"
style="margin-top:20px"
:data-total="dataTotal"
:reset-page-size="resetPageSize"
@table-pagination-update="tablePaginationLoad"
/> // 表格分页:点击分页后拉新业务
tablePaginationLoad (pagenum, pagesize) {
this.pagenum = pagenum - 1
this.pagesize = pagesize
this.featureSearchChange(this.keyWords,this.businessIdSet,false)
}, // 搜索:所有数据的刷新
featureSearchChange (val, businessId, resetPageSize) {
if (resetPageSize) { // 搜索时切换业务
this.pagenum = 0
this.resetPageSize = !this.resetPageSize
}
const businessIdSet = businessId || ''
const paramet = {
'business.id': this.globalPage ? businessIdSet : this.businessIdSet,
'pagenum': this.pagenum,
'pagesize': this.pagesize,
'authority': this.authority, // 个人或公共
'keyword': val || ''
}
this.onLoadData(paramet)
},
// 重置分页
// resetSize(){
// this.$refs.pager.resetSize()
// },
// 加载数据getAllData()
onLoadData (paramet) {
if (paramet) {
this.loadingData = true
getAllData(paramet).then(res => {
if (res && res.data && res.data.err_code === '0' && res.data.info) {
const result = res.data.info
this.dataTotal = res.data.num || 0 // 总条数
const tableData = [] // 展示数据
if (result && result.length > 0) { // 省略遍历自定义result
this.tableBegin = tableData
this.loadingData = false
} else {
this.tableBegin = []
this.loadingData = false
}
} else {
this.tableBegin = []
this.dataTotal = 0 // 总条数
this.$message.error(res.data ? res.data.err_desc : '获取特征数据失败')
this.loadingData = false
}
}).catch(() => {
this.loadingData = false
this.$message.error('获取数据失败')
})
}
}
}

-end-

最新文章

  1. Windows Server 2008 R2 配置AD(Active Directory)域控制器
  2. Oracle之物化视图
  3. 如何在java中使用sikuli进行自动化测试
  4. HDU 5047 推公式+别样输出
  5. servlet学习笔记二
  6. Linux时间相关函数
  7. gdb 技巧
  8. Ubuntu下管理员界面的切换
  9. Mac下chrome的webapp hostadmin 快速切换host
  10. python第三方扩展库及不同类型的测试需安装相对应的第三方库总结
  11. vue echarts 遇到的bug之一 无法渲染的问题
  12. 笔记8 AOP练习2
  13. Map value类型不同的写法
  14. postgreSQL可视化工具pgAdmin3 导入表结构和数据
  15. 遗传算法(GA)
  16. ANSI/ISO C 关键字(汇总)
  17. [转]GitHub上优秀的Go开源项目
  18. edge box
  19. telnet强制中断登录
  20. Java读取excel(兼容03和07格式)

热门文章

  1. odoo开发笔记--ValueError Expected singleton
  2. Robot Framwork关键字驱动+RedwoodHQ安装
  3. Python3 多线程(连接池)操作MySQL插入数据
  4. Tomcat 配置虚拟目录以及虚拟主机
  5. [LeetCode] 93. Restore IP Addresses 复原IP地址
  6. mysql left join和union结合的用法
  7. windows下大数据开发环境搭建(2)——Hadoop环境搭建
  8. eoj monthly 2019.11
  9. springcloud使用之服务的注册发现与消费
  10. Java 8 Optional 的用法