Implementation method of table paging component based on vue2
This article mainly introduces the implementation method of table paging component based on vue2 in detail. It has certain reference value. Interested friends can refer to it.
The example of this article shares the vue2 table with everyone. The specific code of the paging component is for your reference. The specific content is as follows
pagination.js:
##
(function(){
var template = '<p class="page-bar" > \
<p class="info">{{info}}</p>\
<p class="showpages">每页<select class="showpages-select" v-on:change="pageschange" v-model="selected" ><option v-for="item in showpages">{{item}}</option></select>条</p>\
<p 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></p> \
</p>\
'
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
})()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;
}<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>/**
* 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)
}
}
});The above is the detailed content of Implementation method of table paging component based on vue2. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undress AI Tool
Undress images for free
Clothoff.io
AI clothes remover
AI Hentai Generator
Generate AI Hentai for free.
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
1381
52
How do I create and publish my own JavaScript libraries?
Mar 18, 2025 pm 03:12 PM
Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.
How do I optimize JavaScript code for performance in the browser?
Mar 18, 2025 pm 03:14 PM
The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.
What should I do if I encounter garbled code printing for front-end thermal paper receipts?
Apr 04, 2025 pm 02:42 PM
Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...
How do I debug JavaScript code effectively using browser developer tools?
Mar 18, 2025 pm 03:16 PM
The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.
Who gets paid more Python or JavaScript?
Apr 04, 2025 am 12:09 AM
There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.
How do I use source maps to debug minified JavaScript code?
Mar 18, 2025 pm 03:17 PM
The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.
How to merge array elements with the same ID into one object using JavaScript?
Apr 04, 2025 pm 05:09 PM
How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...
The difference in console.log output result: Why are the two calls different?
Apr 04, 2025 pm 05:12 PM
In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...


