表格分页——tablePagination
背景:表格是最为通用的展示方式,为了展示的统一性,以及分页组件的重用,这里写一个分页组件,供比较多或者较少数据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监听改变
表格分页——tablePagination的更多相关文章
- 基于Vue.js的表格分页组件
有一段时间没更新文章了,主要是因为自己一直在忙着学习新的东西而忘记分享了,实在惭愧. 这不,大半夜发文更一篇文章,分享一个自己编写的一个Vue的小组件,名叫BootPage. 不了解Vue.js的童鞋 ...
- Vue.js的表格分页组件
转自:http://www.cnblogs.com/Leo_wl/p/5522299.html 有一段时间没更新文章了,主要是因为自己一直在忙着学习新的东西而忘记分享了,实在惭愧. 这不,大半夜发文更 ...
- Angular.js+Bootstrap实现表格分页
最近一直学习Angular.js,在学习过程中也练习了很多的Demo,这里先贴一下表格+分页. 先上图看看最终结果: 不得不说Angular.js代码风格很受人欢迎,几十行代码清晰简洁的实现了上面的功 ...
- 如何用angularjs制作一个完整的表格之二__表格分页功能
接上一次,这次主要介绍表格分页功能,由于项目需要这个案例是关于前端分页的方式,现在很少会这么用了,但如有需要可以参考其中的思路 html: 1.通过UL来展示页标,其中每个页标的li是通过异步加载从获 ...
- 【转】基于jquery的无刷新表格分页
效果图 css样式 <style> html,body{margin: 0;padding:0} a:focus {outline: none;} /* 通用表格显示 */ table, ...
- ASP.NET MVC 之表格分页
简单效果图:(框架:MVC+NHibernate) 要点: (1)首先建立表格分页Model(GridModel.cs) (2)然后建立数据展示页(PageCloth.cshtml) (3)再建分页版 ...
- dojo表格分页插件报错
dojo表格分页插件报错 (1)dojo/parser::parse() error ReferenceError {stack:(...),message:"layout is not d ...
- dojo表格分页之各个参数代表的意义(一)
下面是dojo表格分页参数代表的意义 //每页可以显示10/15/20/25/30条记录 (1)pageSizes: [10, 15, 20, 25,30], //每页显示的记录从多少到多少,共多少条 ...
- bootstrap table + spring + springmvc + mybatis 实现从前端到后端的表格分页
1.使用准备 前台需要的资源文件,主要有Bootstrap3相关css.js以及bootstrap Table相关css.js: <-- 样式 --> <link rel=" ...
随机推荐
- flutter中的listview的使用
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends Statele ...
- 泡泡一分钟:Topomap: Topological Mapping and Navigation Based on Visual SLAM Maps
Topomap: Topological Mapping and Navigation Based on Visual SLAM Maps Fabian Bl¨ochliger, Marius Feh ...
- 算法习题---4-7RAID技术(UV509)
一:题目 (一)基础知识补充(RAID和奇偶校验) 磁盘管理—磁盘阵列(RAID)实例详解(本题目常用RAID 5技术实现) 奇偶校验(同行数据中同位上的1的个数,偶校验时:1的个数为偶数则校验结果为 ...
- 安卓 android studio 报错 Lint found fatal errors while assembling a release target
报错截图如下: 解决方法:在app的build.gradle中添加如下代码 android{ lintOptions { checkReleaseBuilds false abortOnError f ...
- Docker:学习笔记(1)——基础概念
Docker:学习笔记(1)——基础概念 Docker是什么 软件开发后,我们需要在测试电脑.客户电脑.服务器安装运行,用户计算机的环境各不相同,所以需要进行各自的环境配置,耗时耗力.为了解决这个问题 ...
- jstat介绍
命令可用选项 ➜ ~ jstat -options -class -compiler -gc -gccapacity -gccause -gcmetacapacity -gcnew -gcnewcap ...
- consul分布式集群搭建&简单功能测试&故障恢复【h】
环境准备五台机器: 操作系统 IP Ubuntu 16.04.3 LTS x86_64 192.168.1.185 Ubuntu 16.10 x86_64 192.168.3.152 Ubuntu 1 ...
- zabbix4.2+grafana搭建骚气的监控运维平台
Zabbix 是一个企业级分布式开源监控解决方案,其监控与告警功能十分强大.Grafana是一款开源的可视化软件,可以搭配数据源实现一个数据的展示和分析:Grafana功能强大,有着丰富的插件.两者结 ...
- 【NER】对命名实体识别(槽位填充)的一些认识
命名实体识别 1. 问题定义 广义的命名实体识别是指识别出待处理文本中三大类(实体类.时间类和数字类).七小类(人名.机构名.地名.日期.货币和百分比)命名实体.但实际应用中不只是识别上述所说的实体类 ...
- 高级UI-CardView
CardView是在Android 5.0推出的新控件,为了兼容之前的版本,将其放在了v7包里面,在现在扁平化设计潮流的驱使下,越来越多的软件使用到了CardView这一控件,那么这篇文章就来看看Ca ...