原創做品轉載請註明出處web
先來看一下效果圖:
ajax
功能描述:
1. 點擊頁面序號跳轉到相應頁面;
2. 點擊單左/單右,向後/向前跳轉一個頁面;
3. 點擊雙左/雙右,直接跳轉到最後一頁/第一頁;
3. 一次顯示當前頁面的前三個與後三個頁面;
4. 始終顯示最後一個頁面;express
HTML:api
<!-- 分頁開始 --> <div class="u-pages" style="margin-bottom:20px; margin-top:10px;"> <ul> <li v-if="showPre" class="crt"><a v-on:click="jumpFirst(cur)"> << </a></li> <li v-if="showPre" class="crt"><a v-on:click="minus(cur)"> < </a></li> <template v-for="index in indexs" > <li class="{{classRenderer(index)}}"> <a v-on:click="btnClick(index)" >{{index}}</a> </li> </template> <li v-if="showMoreTail" class="crt">..</li> <li class="{{classRenderer(pageNo)}}"><a @click="btnClick(pageNo)">{{pageNo}}</a></li> <li v-if="showTail" class="crt"><a v-on:click="plus(cur)">></a></li> <li v-if="showTail" class="crt"><a v-on:click="jumpTail(cur)">>></a></li> </ul> </div> <!-- 分頁結束 -->
HTML方法分析:
一、<li class="{{classRenderer(index)}}">
classRenderer()方法實現了當點擊頁面索引是,點擊頁面得到選中效果
二、<a v-on:click="btnClick(index)" >{{index}}</a>
btnClick()方法,實現了點擊頁面索引,跳轉到相應頁面
三、showPre
showTail
showPre控制跳轉到第一頁與跳轉到前一頁的按鈕的顯示與消除
showTail控制跳轉到最後一頁與跳轉到後一頁的按鈕的顯示與消除
四、cur
記錄當前頁序號
五、jumpFirst(cur)
minus(cur)
plus(cur)
jumpTail(cur)
實現按鈕跳轉功能ui
JS:this
module.exports = {
data: function () {
return {
cur:1,
showTail:true,
showMorePre: false,
showMoreTail: false,
}
},
methods:{
jumpFirst:function(data){
var $this = this;
data = 1;
$this.cur = data;
if (data == 1 )
{
$this.$set("showPre", false);
}else
{
$this.$set("showPre", true);
}
$this.$am.ajax({
url:window.$ApiConf.api_order_detail_list,
type:'GET',
data:{start: 1},
success: function(data){
console.log(data);
$this.$set("records", data.record.records);
$this.$set("start", data.record.query.start);
$this.$set("total", data.record.query.total);
$this.$set("limit", data.record.query.limit);
}
})
$this.$set("showTail", true);
return data;
},
minus:function(data){
var $this = this;
data--;
$this.cur = data;
$this.$set("showTail", true);
if(data == 1){
$this.$set("showPre", false);
}else{
$this.$set("showPre", true);
}
$this.$am.ajax({
url:window.$ApiConf.api_order_detail_list,
type:'GET',
data:{start: 1 + $this.limit * (data-1) },
success:function(data){
console.log(data);
$this.$set("records", data.record.records);
$this.$set("start", data.record.query.start);
$this.$set("total", data.record.query.total);
$this.$set("limit", data.record.query.limit);
}
})
return data;
},
plus: function(data){
var $this = this;
data++;
$this.cur = data;
$this.$set("showPre", true);
if (data == $this.pageNo)
{
$this.$set("showTail", false);
}else
{
$this.$set("showTail", true);
}
$this.$am.ajax({
url:/* 這裏寫上你本身請求數據的路徑 */,
type:'GET',
data:{start: 1 + $this.limit * (data-1) },
success:function(data){
console.log(data);
$this.$set("records", data.record.records);
$this.$set("start", data.record.query.start);
$this.$set("total", data.record.query.total);
$this.$set("limit", data.record.query.limit);
}
})
return data;
},
classRenderer:function(index){
var $this = this;
var cur = $this.cur;
if(index != cur){
return 'crt';
}
return '';
},
btnClick:function(data){
var $this = this;
if(data == 1){
$this.$set("showPre", false);
}else{
$this.$set("showPre", true);
}
if (data == $this.pageNo)
{
$this.$set("showTail", false);
}else
{
$this.$set("showTail", true);
}
if (data != $this.cur)
{
$this.cur = data;
$this.$am.ajax({
url:window.$ApiConf.api_order_detail_list,
type:'GET',
data:{start: 1 + $this.limit * (data-1) },
success:function(data){
console.log(data);
$this.$set("records", data.record.records);
$this.$set("start", data.record.query.start);
$this.$set("total", data.record.query.total);
$this.$set("limit", data.record.query.limit);
}
})
}
},
jumpTail:function(data){
var $this = this;
data = $this.pageNo;
$this.cur = data;
if (data == $this.pageNo)
{
$this.$set("showTail", false);
}else
{
$this.$set("showTail", true);
}
$this.$am.ajax({
url:window.$ApiConf.api_order_detail_list,
type:'GET',
data:{start: 1 + $this.limit * (data-1) },
success:function(data){
console.log(data);
$this.$set("records", data.record.records);
$this.$set("start", data.record.query.start);
$this.$set("total", data.record.query.total);
$this.$set("limit", data.record.query.limit);
}
})
$this.$set("showPre", true);
return data;
},
computed: {
//*********************分頁開始******************************//
indexs: function(){
var $this = this;
var ar = []; if ($this.cur > 3) { ar.push($this.cur - 3); ar.push($this.cur - 2); ar.push($this.cur - 1); }else { for (var i = 1; i < $this.cur; i++) { ar.push(i); } } if ($this.cur != $this.pageNo) { ar.push($this.cur); } if ( $this.cur < ( $this.pageNo - 3 ) ) { ar.push($this.cur + 1); ar.push($this.cur + 2); ar.push($this.cur + 3); if ( $this.cur < ( $this.pageNo - 4 ) ) { $this.$set("showMoreTail", true); } }else { $this.$set("showMoreTail", false); for (var i = ($this.cur + 1); i < $this.pageNo; i++) { ar.push(i); } } return ar; } //*********************分頁結束******************************// } }
module.exports = { data: function () { return { cur:1, showTail:true, showMorePre: false, showMoreTail: false, } }, methods:{ jumpFirst:function(data){ var$this= this; data=1; $this.cur=data; if (data==1 ) { $this.$set("showPre", false); }else { $this.$set("showPre", true); } $this.$am.ajax({ url:window.$ApiConf.api_order_detail_list, type:'GET', data:{start: 1}, success: function(data){ console.log(data); $this.$set("records", data.record.records); $this.$set("start", data.record.query.start); $this.$set("total", data.record.query.total); $this.$set("limit", data.record.query.limit); } }) $this.$set("showTail", true); returndata; }, minus:function(data){ var$this= this; data--; $this.cur=data; $this.$set("showTail", true); if(data==1){ $this.$set("showPre", false); }else{ $this.$set("showPre", true); } $this.$am.ajax({ url:window.$ApiConf.api_order_detail_list, type:'GET', data:{start: 1+$this.limit* (data-1) }, success:function(data){ console.log(data); $this.$set("records", data.record.records); $this.$set("start", data.record.query.start); $this.$set("total", data.record.query.total); $this.$set("limit", data.record.query.limit); } }) returndata; }, plus: function(data){ var$this= this; data++; $this.cur=data; $this.$set("showPre", true); if (data==$this.pageNo) { $this.$set("showTail", false); }else { $this.$set("showTail", true); } $this.$am.ajax({ url:/* 這裏寫上你本身請求數據的路徑 */, type:'GET', data:{start: 1+$this.limit* (data-1) }, success:function(data){ console.log(data); $this.$set("records", data.record.records); $this.$set("start", data.record.query.start); $this.$set("total", data.record.query.total); $this.$set("limit", data.record.query.limit); } }) returndata; }, classRenderer:function(index){ var$this= this; var cur =$this.cur; if(index != cur){ return'crt'; } return''; }, btnClick:function(data){ var$this= this; if(data==1){ $this.$set("showPre", false); }else{ $this.$set("showPre", true); } if (data==$this.pageNo) { $this.$set("showTail", false); }else { $this.$set("showTail", true); } if (data!=$this.cur) { $this.cur=data; $this.$am.ajax({ url:window.$ApiConf.api_order_detail_list, type:'GET', data:{start: 1+$this.limit* (data-1) }, success:function(data){ console.log(data); $this.$set("records", data.record.records); $this.$set("start", data.record.query.start); $this.$set("total", data.record.query.total); $this.$set("limit", data.record.query.limit); } }) } }, jumpTail:function(data){ var$this= this; data=$this.pageNo; $this.cur=data; if (data==$this.pageNo) { $this.$set("showTail", false); }else { $this.$set("showTail", true); } $this.$am.ajax({ url:window.$ApiConf.api_order_detail_list, type:'GET', data:{start: 1+$this.limit* (data-1) }, success:function(data){ console.log(data); $this.$set("records", data.record.records); $this.$set("start", data.record.query.start); $this.$set("total", data.record.query.total); $this.$set("limit", data.record.query.limit); } }) $this.$set("showPre", true); returndata; }, computed: { //*********************分頁開始******************************// indexs: function(){ var$this= this; var ar =[]; if ($this.cur > 3) { ar.push($this.cur - 3); ar.push($this.cur - 2); ar.push($this.cur - 1); }else { for (var i = 1; i < $this.cur; i++) { ar.push(i); } } if ($this.cur != $this.pageNo) { ar.push($this.cur); } if ( $this.cur < ( $this.pageNo - 3 ) ) { ar.push($this.cur + 1); ar.push($this.cur + 2); ar.push($this.cur + 3); if ( $this.cur < ( $this.pageNo - 4 ) ) { $this.$set("showMoreTail", true); } }else { $this.$set("showMoreTail", false); for (var i = ($this.cur + 1); i < $this.pageNo; i++) { ar.push(i); } } return ar; } //*********************分頁結束******************************// } } url