//js代码
var vm = new Vue({
el: '#app',data: {
msg:'hello',curItem:'',curPage:1,total:211,limit:10,pageGroup:10//分页条数 默认7个分页数
},created: function () {
console.log('created')
},mounted: function () {
console.log('mounted')
},computed:{
totalPage:function(){
return Math.ceil(this.total / this.limit)
},pagelist:function(){
var list = [];
var count = Math.floor(this.pageGroup/2),center = this.curPage;
var left = 1,right = this.totalPage;
if(this.totalPage>this.pageGroup){
if(this.curPage>count+1){
if(this.curPage < this.totalPage - count){
left = this.curPage - count;
right = this.curPage + count-1;
}else{
left = this.totalPage - this.pageGroup+1;
}
}else{
right = this.pageGroup;
}
}
// 遍历添加到数组里
while(left<=right){
list.push({
text:left,val:left
});
left++;
}
return list;
}
},methods:{
changePage:function(idx){
if(idx!=this.curPage && idx>0 && idx<=this.totalPage){
this.curPage = idx;
}
},login:function(){
alert('login')
}
}
})</code></pre>
<h3 id="最后">最后
以上,就是前端分页效果实现,下篇文章我将把分页抽离出来做成一个分页组件,毕竟分页在很多页面都需要用到
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!