vue實(shí)現(xiàn)分頁(yè)的三種效果
本文實(shí)例為大家分享了vue實(shí)現(xiàn)分頁(yè)效果的具體代碼,供大家參考,具體內(nèi)容如下
第一種效果:數(shù)據(jù)量不大時(shí)可采用
<!doctype html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"> <script src="vue.min.js" type="text/javascript"></script> <title>vue分頁(yè)</title> <style type="text/css"> ul{list-style:none;margin:0;} .pagetation_info{width:100%;height:27px;padding:20px 0;} ul.pagetation_box{float:right;height:100%;padding:0 60px;} ul.pagetation_box li{float:left;height:100%;border:1px solid #e6ecef;border-radius: 3px;background-color: #f8f8f8;margin:0 5px;padding:0 10px;color:#263238;cursor: pointer;text-align: center;line-height: 22px;} ul.pagetation_box li a{text-decoration: none;color:#263238;font-size: 12px;} ul.pagetation_box li.active{background-color: #FF4646;border-color:#FF4646;} ul.pagetation_box li.active a{color:#fff;} ul.pagetation_box li.prev,ul.pagetation_box li.next{width:7px;} ul.pagetation_box li:hover{background-color: #FF4646;border-color:#FF4646;} ul.pagetation_box li:hover a{color:#fff;} .num_total{float:right;height:100%;padding-top:3px;padding-bottom:3px;} .num_total>span{color:#FC5B27;} </style> </head> <body id="app-body"> <div class="pagetation_info clearfix"> <ul class="pagetation_box"> <li class="firstPage" @click=" page.currentpage = 0 "><a href="javascript:;" >首頁(yè)</a></li> <li class="prev" v-show=" page.currentpage > 0 " @click=" page.currentpage-- "><a href="javascript:;" ><</a></li> <li v-for="d in page.totalpage" @click=" page.currentpage = $index " :class=" page.currentpage == $index ? 'active' : '' "><a href="javascript:;" >{{$index + 1}}</a></li> <li class="next" v-show=" page.currentpage < page.totalpage - 1 " @click=" page.currentpage++ "><a href="javascript:;" >></a></li> <li class="lastPage" @click=" page.currentpage = page.totalpage - 1 "><a href="javascript:;" >尾頁(yè)</a></li> </ul> <div class="num_total"> 共 <span>{{page.totalrecord}}</span> 條信息,共 <span>{{page.totalpage}}</span> 頁(yè) </div> </div> <script> new Vue({ el: "#app-body", data : { "page" : { "totalrecord" : 100, "currentpage" : 0, "pagesize" : 20, "totalpage" : 5, }, }, watch : { "page.currentpage" : function(val){ var _this=this; _this._getList(); }, }, methods : { _getList:function(){} }, ready : function(){ var _this = this; } }); </script> </body> </html>
第二種效果:當(dāng)數(shù)據(jù)量較大時(shí)使用
<!doctype html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"> <script src="vue.min.js" type="text/javascript"></script> <title>vue分頁(yè)</title> <style type="text/css"> ul{list-style:none;margin:0;} .pagetation_info{width:100%;height:24px;padding:20px 0;} ul.pagetation_box{float:right;height:100%;padding:0 60px;} ul.pagetation_box li{float:left;height:100%;border:1px solid #e6ecef;background-color: #f8f8f8;margin:0 5px;padding:0 10px;color:#263238;cursor: pointer;text-align: center;line-height: 22px;} ul.pagetation_box li a{text-decoration: none;color:#263238;font-size: 12px;} ul.pagetation_box li.active{background-color: #FF4646;border-color:#FF4646;} ul.pagetation_box li.active a{color:#fff;} ul.pagetation_box li.prev,ul.pagetation_box li.next{width:7px;} ul.pagetation_box li:hover{background-color: #FF4646;border-color:#FF4646;} ul.pagetation_box li:hover a{color:#fff;} ul.pagetation_box li.more{width:24px;padding:0;background: url(../img/public/page_more.png) no-repeat center center;border:none;} .num_total{float:right;height:100%;line-height:22px;padding-top:3px;padding-bottom:3px;} .num_total>span{color:#FC5B27;} </style> </head> <body id="app-body"> <div class="pagetation_info clearfix"> <ul class="pagetation_box"> <li class="firstPage" @click="page.currentPage=1"><a href="javascript:;" >首頁(yè)</a></li> <li class="prev" v-show="page.currentPage != 1" @click="page.currentPage-- && _gotoPage(page.currentPage)"><a href="javascript:;" ><</a></li> <li v-for="index in pages" @click="_gotoPage(index)" :class="{'active':page.currentPage == index}"><a href="javascript:;" >{{index}}</a></li> <li class="next" v-show="page.allPages != page.currentPage && page.allPages != 0 " @click="page.currentPage++ && _gotoPage(page.currentPage)"><a href="javascript:;" >></a></li> <li class="lastPage" @click="page.currentPage=page.allPages"><a href="javascript:;" >尾頁(yè)</a></li> </ul> <div class="num_total"> 共 <span>{{page.allRecords}}</span> 條信息,共 <span>{{page.allPages}}</span> 頁(yè) </div> </div> <script> new Vue({ el : "#app-body", data : { "page":{ "currentPage":1, "pagesize":10, "allRecords":100, "allPages":10, "showItem":4, } }, watch : { "page.currentpage" : function(val){ var _this=this; _this._getList(); }, }, computed:{ pages:function(){ var _this=this; var p=[]; if( _this.page.currentPage < _this.page.showItem ){ var i = Math.min(_this.page.showItem,_this.page.allPages); while(i){ p.unshift(i--); } }else{ var middle = _this.page.currentPage - Math.floor(_this.page.showItem / 2 ), i = _this.page.showItem; console.log(middle,i); if( middle > (_this.page.allPages - _this.page.showItem) ){ middle = (_this.page.allPages - _this.page.showItem) + 1 } while(i--){ p.push( middle++ ); } } return p; }, }, methods : { _gotoPage:function(i){ var _this=this; if(i == _this.page.currentPage) return; _this.page.currentPage = i; }, }, ready : function(){ var _this = this; _this.pages; } }); </script> </body> </html>
第三種效果:當(dāng)數(shù)據(jù)量很大時(shí)使用
<!doctype html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"> <script src="vue.min.js" type="text/javascript"></script> <title>vue分頁(yè)</title> <style type="text/css"> ul{list-style:none;margin:0;} .pagetation_info{width:100%;height:30px;padding:20px 0;} ul.pagetation_box{float:right;height:100%;padding:0 60px;} ul.pagetation_box li{float:left;height:100%;border:1px solid #e6ecef;background-color: #f8f8f8;margin:0 5px;padding:0 10px;color:#263238;cursor: pointer;text-align: center;line-height: 27px;} ul.pagetation_box li a{text-decoration: none;color:#263238;font-size: 12px;} ul.pagetation_box li.active{background-color: #03a9f4;border-color:#03a9f4;} ul.pagetation_box li.active a{color:#fff;} ul.pagetation_box li.more{background-color: #fff} ul.pagetation_box li.prev,ul.pagetation_box li.next{width:7px;} ul.pagetation_box li.prevDisabled,ul.pagetation_box li.nextDisabled{width:7px;} ul.pagetation_box li.prevDisabled a,ul.pagetation_box li.nextDisabled a{color:#ccc;} ul.pagetation_box li.prevDisabled:hover, ul.pagetation_box, li.nextDisabled:hover{background-color: #f8f8f8;border-color:#e6ecef;} ul.pagetation_box li.prevDisabled:hover a,ul.pagetation_box li.nextDisabled:hover a{color:#ccc;} ul.pagetation_box li:hover{background-color: #03a9f4;border-color:#03a9f4;} ul.pagetation_box li.more:hover{background-color: #fff;border:none;} ul.pagetation_box li:hover a{color:#fff;} ul.pagetation_box li.more{padding:0;border:none;line-height:22px;} .num_total{float:right;height:100%;line-height:22px;padding-top:3px;padding-bottom:3px;} .num_total>span{color:#FC5B27;} </style> </head> <body id="app-body"> <div class="pagetation_info clearfix"> <ul class="pagetation_box"> <li class="prev" v-if="page.prevBtn==true" @click="_gotoPage('prev')"><a href="javascript:;" ><</a></li> <li class="prevDisabled" v-if="page.prevBtn==false"><a href="javascript:;" ><</a></li> <li :class="{active:page.currentPage==index}" v-for="index in page.p1" @click="_gotoPage(index)"><a href="javascript:;" >{{index}}</a></li> <li class="more" v-if="page.isShowMore1">...</li> <li :class="{active:page.currentPage==index}" v-for="index in page.p2" @click="_gotoPage(index)"><a href="javascript:;" >{{index}}</a></li> <li class="more" v-if="page.isShowMore2">...</li> <li :class="{active:page.currentPage==index}" v-for="index in page.p3" @click="_gotoPage(index)"><a href="javascript:;" >{{index}}</a></li> <li class="next" v-if="page.nextBtn==true" @click="_gotoPage('next')"><a href="javascript:;" >></a></li> <li class="nextDisabled" v-if="page.nextBtn==false"><a href="javascript:;" >></a></li> </ul> <div class="num_total"> 共 <span>{{page.allItems}}</span> 條信息,共 <span>{{page.allPages}}</span> 頁(yè) </div> </div> <script> var App=new Vue({ el : "#app-body", data : { "page" : { "currentPage":1, "allPages":10, "allItems":100, "pagesize":10, "showBtn":5, "nextBtn":true, "prevBtn":false, "isShowMore1":false, "isShowMore2":false, "p1":[], "p2":[], "p3":[], }, }, watch : { "page.currentpage" : function(val){ var _this=this; _this._getList(); }, }, computed:{ pagination:function(){ var _this=this; var i = _this.page.showBtn-2; if(_this.page.currentPage==_this.page.allPages){_this.page.nextBtn=false;} var p1=[],p2=[],p3=[]; if( _this.page.allPages < _this.page.showBtn ){ _this.page.isShowMore1=false; _this.page.isShowMore2=false; i = _this.page.allPages; while(i){ p1.unshift(i--); } }else if(_this.page.allPages > _this.page.showBtn && _this.page.allPages < _this.page.showBtn+1){ _this.page.isShowMore1=false; _this.page.isShowMore2=true; if(_this.page.currentPage<3){ p1=[1,2,3]; p3.push(_this.page.allPages); }else{ p1=[1]; i=_this.page.showBtn-2; while(i--){ p3.unshift( _this.page.allPages-- ); } } }else{ if(_this.page.currentPage<3){ p1=[1,2,3]; p3.push(_this.page.allPages); _this.page.isShowMore1=false; _this.page.isShowMore2=true; }else if(_this.page.currentPage>_this.page.allPages-2){ _this.page.isShowMore1=true; _this.page.isShowMore2=false; p1=[1]; i=3; var allPages = _this.page.allPages; while(i--){ p3.unshift( allPages-- ); } }else{ _this.page.isShowMore1=true; _this.page.isShowMore2=true; if(_this.page.currentPage==3){ _this.page.isShowMore1=false; }else if(_this.page.currentPage==_this.page.allPages-1){ _this.page.isShowMore2=false; } p1=[1]; p3.push(_this.page.allPages); var middle=parseInt((_this.page.showBtn-2)/2); var start=_this.page.currentPage-middle; i = _this.page.showBtn-2; while(i--){ p2.push(start++); } } } _this.page.p1=p1; _this.page.p2=p2; _this.page.p3=p3; } }, methods : { _gotoPage:function(n){ var _this=this; if(n==_this.page.currentPage){ return; } if(n==1){ _this.page.prevBtn=false; }else{ _this.page.prevBtn=true; } if(n==_this.page.allPages){ _this.page.nextBtn=false; }else{ _this.page.nextBtn=true; } if(typeof n=='number'){ _this.page.currentPage=n; }else if(n=='next'){ _this.page.currentPage++; }else if(n=='prev'){ _this.page.currentPage--; } if(_this.page.currentPage==_this.page.allPages){_this.page.nextBtn=false;} _this.pagination; }, }, ready : function(){ var _this = this; _this.pagination; } }); </script> </body> </html>
關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue form 表單提交+ajax異步請(qǐng)求+分頁(yè)效果
- 利用vue + element實(shí)現(xiàn)表格分頁(yè)和前端搜索的方法
- Vue+element-ui 實(shí)現(xiàn)表格的分頁(yè)功能示例
- Vue2.5 結(jié)合 Element UI 之 Table 和 Pagination 組件實(shí)現(xiàn)分頁(yè)功能
- 基于Vue.js的表格分頁(yè)組件
- 用Vue寫一個(gè)分頁(yè)器的示例代碼
- vuejs2.0實(shí)現(xiàn)一個(gè)簡(jiǎn)單的分頁(yè)示例
- Vue.js實(shí)現(xiàn)無(wú)限加載與分頁(yè)功能開發(fā)
- Vue.js實(shí)現(xiàn)多條件篩選、搜索、排序及分頁(yè)的表格功能
- Vue.js實(shí)現(xiàn)分頁(yè)查詢功能
相關(guān)文章
vue如何給element-ui中的el-tabs動(dòng)態(tài)設(shè)置label屬性
這篇文章主要介紹了vue如何給element-ui中的el-tabs動(dòng)態(tài)設(shè)置label屬性,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08解決vue修改數(shù)據(jù)頁(yè)面不重新渲染問題
這篇文章詳細(xì)介紹了vue渲染機(jī)制和如何解決數(shù)據(jù)修改頁(yè)面不刷新問題的多種方法,想了解更多的小伙伴可以借鑒閱讀2023-03-03Vue+ElementUI使用vue-pdf實(shí)現(xiàn)預(yù)覽功能
這篇文章主要為大家詳細(xì)介紹了Vue+ElementUI使用vue-pdf實(shí)現(xiàn)預(yù)覽功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11Vue3實(shí)現(xiàn)優(yōu)雅加載圖片的動(dòng)畫效果
這篇文章主要為大家詳細(xì)介紹了Vue3如何實(shí)現(xiàn)加載圖片時(shí)添加一些動(dòng)畫效果,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考下2023-10-10vue動(dòng)態(tài)組件之:is在組件中的使用場(chǎng)景
這篇文章主要介紹了vue動(dòng)態(tài)組件之:is在組件中的使用場(chǎng)景,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07Javascript結(jié)合Vue實(shí)現(xiàn)對(duì)任意迷宮圖片的自動(dòng)尋路
本文將結(jié)合實(shí)例代碼介紹Javascript結(jié)合Vue實(shí)現(xiàn)對(duì)任意迷宮圖片的自動(dòng)尋路,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06Vue輸入框狀態(tài)切換&自動(dòng)獲取輸入框焦點(diǎn)的實(shí)現(xiàn)方法
這篇文章主要介紹了Vue輸入框狀態(tài)切換&自動(dòng)獲取輸入框焦點(diǎn)的實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-05-05Vue3+Vue-cli4項(xiàng)目中使用騰訊滑塊驗(yàn)證碼的方法
這篇文章主要介紹了Vue3+Vue-cli4項(xiàng)目中使用騰訊滑塊驗(yàn)證碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-11-11Vue2實(shí)現(xiàn)圖片的拖拽,縮放和旋轉(zhuǎn)效果的示例代碼
這篇文章主要為大家介紹了如何基于vue2?實(shí)現(xiàn)圖片的拖拽、旋轉(zhuǎn)、鼠標(biāo)滾動(dòng)放大縮小等功能。文中的示例代碼講解詳細(xì),感興趣的小伙伴可以嘗試一下2022-11-11