DDR爱好者之家 Design By 杰米
本文实例为大家分享了vue2 table分页组件的具体代码,供大家参考,具体内容如下
pagination.js:
(function(){ var template = '<div class="page-bar" > <div class="info">{{info}}</div> <div class="showpages">每页<select class="showpages-select" v-on:change="pageschange" v-model="selected" ><option v-for="item in showpages">{{item}}</option></select>条</div> <div class="pagesbtn"><ul v-on:click="setpage"> <li ><a v-bind:class="setButtonClass(0)" v-on:click="firstPage()">首页</a></li> <li><a v-bind:class="setButtonClass(0)" v-on:click="prvePage()">上一页</a></li> <li v-for="index in indexs" v-bind:class="{ active: cur == index }"> <a v-on:click="btnclick(index)" >{{ index < 1 "..." : index }}</a> </li> <li ><a v-bind:class="setButtonClass(1)" v-on:click="nextPage()">下一页</a></li> <li ><a v-bind:class="setButtonClass(1)" v-on:click="lastPage()">尾页</a></li> </ul></div> </div> ' var pagination = Vue.extend({ template: template, props: ["cur", "all", "selected", "showpages", "info"], computed: { indexs: function () { var left = 1 var right = this.all var ar = [] if (this.all >= 11) { if (this.cur > 5 && this.cur < this.all - 4) { left = this.cur - 5 right = this.cur + 4 } else { if (this.cur <= 5) { left = 1 right = 10 } else { right = this.all left = this.all - 9 } } } while (left <= right) { ar.push(left) left++ } if (ar[0] > 1) { ar[0] = 1; ar[1] = -1; } if (ar[ar.length - 1] < this.all) { ar[ar.length - 1] = this.all; ar[ar.length - 2] = 0; } return ar } }, methods: { btnclick: function (page) { this.cur = page; }, nextPage: function () { if (this.cur >= this.all) { this.cur=this.all; }else{ this.cur++; } }, prvePage: function () { if (this.cur <= 1) { this.cur=1; }else{ this.cur--; } }, firstPage: function () { this.cur=1; }, lastPage: function () { this.cur=this.all; }, setButtonClass: function (isNextButton) { if (isNextButton) { return this.cur >= this.all "page-button-disabled" : "" } else { return this.cur <= 1 "page-button-disabled" : "" } }, setpage:function () { this.$emit('mypage', this.cur); }, pageschange:function () { this.$emit('pageschange', this.selected); } } }) window.Pagination = pagination })()
pagination.css:
ul, li { margin: 0; padding: 0; } .page-bar { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; float: right; border-radius: 4px; } .page-bar .info{ float: left; margin-left:16px; font-size: 16px; height: 100%; } .page-bar .showpages{ float: left; font-size: 16px; margin-left: 16px; height: 100%; } .page-bar .showpages .showpages-select{ width: 70px; margin: 0 10px; height: 28px } .page-bar .pagesbtn{ float: left; margin-left:16px; width: 650px; height: 100%; } .page-bar .pagesbtn ul{ text-align: center; width: 100%; } .page-button-disabled { color:#ddd !important; } .page-bar li { list-style: none; display: inline-block; } .page-bar li:first-child > a { margin-left: 0; } .page-bar a { border: 1px solid #ddd; text-decoration: none; position: relative; float: left; padding: 6px 12px; line-height: 1.42857143; color: #337ab7; cursor: pointer; } .page-bar a:hover { background-color: #eee; } .page-bar .active a { color: #fff; cursor: default; background-color: #1e7aca; border-color: #1e7aca; } .page-bar i { font-style: normal; color: #1e7aca; margin: 0 4px; font-size: 12px; }
index.html:
<table class="table table-bordered table-hover "id="ggztable" v-show="isAddSpecifications"> <thead> <tr> <th>规格值</th> <th>操作</th> </tr> </thead> <tbody> <tr v-for="(item,nn) in limitTemps"> <td>{{item.value}}</td> <td> <img src='../img/common_edit@25.png' data-toggle="modal" data-target="#editSonModal" @click="editSonModal(item,nn)" alt='修改'> <img src='../img/common_del@25.png' data-toggle="modal" data-target="#delSonModal" @click="delSonModal(nn)" alt='删除'> </td> </tr> </tbody> </table> <vue-pagination :cur="specificationValCur":all="specificationValAll":info="specificationValInfo" :showpages="specificationValShowpages":selected="specificationValselected" v-on:mypage="getPage" v-on:pageschange="getspecificationValShowPages"> </vue-pagination>
index.js
/** * Created by komi on 2017-03-05 0005. */ var vm = new Vue({ el: ".main", data: { specificationValCur: 1,//当前页 specificationValAll: 1,//总页数 specificationValselected: 10,//默认每页显示的页数 specificationValTotalRecond: 1,//总记录数 specificationValShowpages: [10, 30, 50, 100], //每页显示的页数 specificationValInfo: "", limitTemps: [], temps:[]//数据源 }, watch: { temps: "setPage" }, components: { 'vue-pagination': Pagination }, methods: { setPage: function () { this.specificationValInfo = "记录数为:" + this.temps.length + "条"; this.specificationValTotalRecond = this.temps.length; this.setPageBtn(); this.setPageLimit(this.specificationValTotalRecond,this.specificationValselected,1) }, getPage:function (msg) { this.specificationValCur=msg;//这里必须,否则按钮无法高亮 this.setPageLimit(this.specificationValTotalRecond,this.specificationValselected,msg) }, setPageLimit: function (total,select,cur) {//这里为实现分页切换table的主要实现 if(total<=select){ this.limitTemps=this.temps; return }else { var arr = []; var a=select*(cur-1); var b=select*cur; for (var i = a; i < b; i++) { if(typeof(this.temps[i])!="undefined"){ arr[i - a] = this.temps[i] } } this.limitTemps = arr; } console.log("total:"+total+"select"+select+"cur"+cur) }, setPageBtn: function () { if (this.specificationValTotalRecond > this.specificationValselected) { if (this.specificationValTotalRecond % this.specificationValselected == 0) { this.specificationValAll = this.specificationValTotalRecond / this.specificationValselected } else { this.specificationValAll = parseInt(this.specificationValTotalRecond / this.specificationValselected) + 1 } } else { this.specificationValAll = 1 } }, getspecificationValShowPages: function (pages) { this.specificationValselected = pages; this.setPageBtn(); this.setPageLimit(this.specificationValTotalRecond,this.specificationValselected,1) } } });
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月27日
2024年11月27日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]