vue 2 기반 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/[email protected]' data-toggle="modal"
data-target="#editSonModal" @click="editSonModal(item,nn)" alt=' '>
<img src='../img/[email protected]' 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)
}
}
});
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Angular: 나만의 상황에 맞는 메뉴 만들기꽤 놀라운 주제이며 대규모 응용 프로그램에 많이 필요합니다. 모든 개발자는 어떻게든 html 테이블을 사용하여 레코드를 표시하고 편집, 보기 또는 다운로드 및 목록 진행과 같은 작업 버튼을 사용했을 수 있으며 모든 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.