
vue分页功能
发布日期:2021-05-08 00:22:18
浏览次数:21
分类:精选文章
本文共 2841 字,大约阅读时间需要 9 分钟。
- 使用组件分页
- 自己写分页
一、组件分页
data(){ return{ tableData: [], total: 0,//总数 pageNum: 1,//当前页 pageSize: 15,//每页显示数量}} mounted: function () { this.query();//加载页面时,获取数据 }, methods:{ //切换页码 changePageNum: function (val) { this.pageNum = val; this.query(); }, //通过接口,获取数据 query: function () { var data = { name: this.name || '', fleetId: this.FleetId, pageNum: this.pageNum,//当前页 pageSize: this.pageSize//查询个数 }; RoleManage.getRole(data) .then(res => { var data = res; if (res.success) { this.tableData = data.obj.list; this.total = data.obj.total; this.name =''; } else { this.$message('查询失败'); } }).catch(err => { // 异常情况 console.log(err); }); }, }
组件分页效果
二、自己构建分页
有些时候需要根据需求自己写分页
- 分页样式
- 上下切页
//调度-系统通讯录分页 dispatchCourentPage: 1, //调度-系统通讯录当前选中标签标记 dispatchCourentIndex: 1, //调度-系统通讯录更多标记项:组id dispatchMorecommandGroupId: '', dispatchTotlePage: 0,//上页 handleLastPage() { if (this.dispatchCourentPage === 1) return; this.dispatchCourentPage -= 1; let index = this.dispatchCourentIndex; if (this.dispatchMorecommandGroupId != '') { this.queryBookMoreBygroupId(this.dispatchMorecommandGroupId); } else { this.queryBookmember(index); } },//下页 handleNextPage() { if (this.dispatchCourentPage === this.dispatchTotlePage) return; this.dispatchCourentPage += 1; let index = this.dispatchCourentIndex; if (this.dispatchMorecommandGroupId != '') { this.queryBookMoreBygroupId(this.dispatchMorecommandGroupId); } else { this.queryBookmember(index); } } ,
三、使用监听属性控制分页显示
computed: { limitData() { let data = [...this.table1Datas]; return data; }, // 因为要动态计算总页数,所以还需要一个计算属性来返回最终给 Table 的 data dataWithPage() { const data = this.limitData; const start = this.current * this.size - this.size; const end = start + this.size; return [...data].slice(start, end); }, }
四、js控制分页,计算总页数
- 方法一
/** *根据数据条数与每页多少条数据计算页数 * totalnum 数据条数 * limit 每页多少条 */ pageCount(totalnum, limit) { return totalnum > 0 ? ((totalnum < limit) ? 1 : ((totalnum % limit) ? (parseInt(totalnum / limit) + 1) : (totalnum / limit))) : 0; },
- 方法2
/** * 分页的总页数算法 * 总记录数:totalRecord * 每页最大记录数:maxResult */ function pageCount() { totalPage = (totalRecord + maxResult -1) / maxResult; }
- 方法3
推荐
totalPage = Math.floor((totalRecord +maxResult -1) /maxResult );
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2025年04月20日 12时17分04秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Leaflet中使用Leaflet.draw插件实现图形交互绘制和编辑(修改图形坐标点)
2023-01-30
Leaflet中使用Leaflet.fullscreen插件实现全屏效果
2025-04-04
Leaflet中使用Leaflet.MagnifyingGlass实现放大镜效果
2025-04-04
Leaflet中原生方式实现测距
2025-04-04
Leaflet中实现矩形闪烁动画效果
2025-04-04
Leaflet中通过leaflet-measure插件实现测距测面效果
2025-04-04
leaflet之家目录
2025-04-04
leaflet军事标绘-直线箭头修改(leaflet篇.87)
2025-04-04
leaflet军事标绘-突击方向绘制(leaflet篇.88)
2025-04-04
leaflet军事标绘-细直线箭头绘制(leaflet篇.82)
2025-04-04
leaflet删除所有图层(leaflet篇.25)
2025-04-04
leaflet加载接入天地图(leaflet篇.1)
2025-04-04
leaflet加载接入百度地图(leaflet篇.2)
2025-04-04
leaflet加载接入腾讯矢量、腾讯影像地图(leaflet篇.4)
2025-04-04
leaflet动态热力图分析(leaflet篇.16)
2025-04-04
leaflet动态热力图(大数据版)(leaflet篇.17)
2025-04-04
leaflet动态画线(leaflet篇.59)
2025-04-04
leaflet区域聚合点(点击后散开并进行合理定位)(leaflet篇.22)
2025-04-04
leaflet叠加geojson图层并居中到屏幕三分之一的位置(leaflet篇.67)
2025-04-04
leaflet叠加geojson图层(leaflet篇.38)
2025-04-04