3.上一页和下一页处理
这个对比第一页需要加入特殊的处理,当前是第一页,这个按钮就不可用状态,下一页一样的逻辑判断当前是不是在最后一页:
调用位置加入事件,在加一个是否可用的类名:
全部代码:
<template> <div class="DiReactPage"> <div class="DiReactPage-btn" v-on:click="clickFirst">第一页</div> <div class="DiReactPage-btn" v-on:click="clickPrev" v-bind:class="{disable:currentpage==1}">上一页</div> <div class="DiReactPage-page"> <span v-for="(item,index) in pages" v-bind:class="{active:currentpage==item}" v-on:click="clickCurrent(item)">{{item}}</span> </div> <div class="DiReactPage-btn" v-on:click="clickNext" v-bind:class="{disable:currentpage==allpage}">下一页</div> <div class="DiReactPage-btn" v-on:click="clickLast">最后一页</div> <div class="DiReactPage-btn">总4页</div> <input class="DiReactPage-input" type="text" /> <button class="DiReactPage-btn">跳转</button> </div> </template> <script> export default { name: 'divuePage', computed:{ pages:function(){ var arr=[]; if(this.allpage>5){ if(this.currentpage+5>this.allpage){ for(var i=this.currentpage;i<=this.allpage;i++){ arr.push(i); }; }else{ for(var i=this.currentpage;i<this.currentpage+5;i++){ arr.push(i); }; }; }else{ for(var i=1;i<=this.allpage;i++){ arr.push(i); }; } return arr; } }, props:["currentpage","allpage"], methods:{ clickFirst:function(){//点击第一页 this.$emit("getajaxlist",1); }, clickCurrent:function(item){ this.$emit("getajaxlist",item); }, clickLast:function(){//点击最后一页 this.$emit("getajaxlist",this.allpage); }, clickPrev:function(){//点击上一页 if(this.currentpage-1<1){ return false; } this.$emit("getajaxlist",this.currentpage-1); }, clickNext:function(){//点击下一页 if(this.currentpage+1>this.allpage){ return false; } this.$emit("getajaxlist",this.currentpage+1); } } } </script> <style> .DiReactPage{ height:30px; line-height:30px; text-align:center;} .DiReactPage .DiReactPage-btn{ display:inline-block; height:30px; line-height:30px; padding:0 5px; margin:0 5px; border-radius:4px; background:#09F; cursor:pointer;} .DiReactPage .DiReactPage-btn.disable{ background:#999;cursor:not-allowed;} .DiReactPage .DiReactPage-page{ display:inline-block; height:30px; line-height:30px; margin:0 20px;} .DiReactPage .DiReactPage-page span{display:inline-block; height:30px; line-height:30px; padding:0 5px; margin:0 5px; color:#000; cursor:pointer;} .DiReactPage .DiReactPage-page span.active{ color:#09F; } .DiReactPage .iReactPage-input{ width:100px; border:1px solid #666; border-radius:4px;height:30px; line-height:30px; } </style>
内容版权声明:除非注明,否则皆为本站原创文章。