热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

基于vue2的table分页组件实现方法

这篇文章主要为大家详细介绍了基于vue2的table分页组件实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了vue2 table分页组件的具体代码,供大家参考,具体内容如下

pagination.js:

(function(){
 var template = '
\
{{info}}
\
每页
\ \
\ ' 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 1) { ar[0] = 1; ar[1] = -1; } if (ar[ar.length - 1] = 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 &#63; "page-button-disabled" : "" } else { return this.cur <= 1 &#63; "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:

规格值 操作
{{item.value}} 修改 删除

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  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)
  }
 }
});

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


推荐阅读
author-avatar
圈圈
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有