這篇文章主要介紹vuejs2.0如何實(shí)現(xiàn)分頁(yè)組件,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
發(fā)展壯大離不開(kāi)廣大客戶長(zhǎng)期以來(lái)的信賴與支持,我們將始終秉承“誠(chéng)信為本、服務(wù)至上”的服務(wù)理念,堅(jiān)持“二合一”的優(yōu)良服務(wù)模式,真誠(chéng)服務(wù)每家企業(yè),認(rèn)真做好每個(gè)細(xì)節(jié),不斷完善自我,成就企業(yè),實(shí)現(xiàn)共贏。行業(yè)涉及成都食品包裝袋等,在重慶網(wǎng)站建設(shè)、成都全網(wǎng)營(yíng)銷(xiāo)推廣、WAP手機(jī)網(wǎng)站、VI設(shè)計(jì)、軟件開(kāi)發(fā)等項(xiàng)目上具有豐富的設(shè)計(jì)經(jīng)驗(yàn)。
首先使用基礎(chǔ) Vue 構(gòu)造器,創(chuàng)建一個(gè)“子類(lèi)”,Vue.extend( options )
var barHtml = '<div class="page-bar">'+ '<ul>'+ '<li v-if="cur>1"><a v-on:click="cur--,pageClick()">上一頁(yè)</a></li>'+ '<li v-if="cur==1"><a class="banclick">上一頁(yè)</a></li>'+ '<li v-for="index in indexs" v-bind:class="{ active: cur == index}">'+ '<a v-on:click="btnclick(index)">{{ index }}</a>'+ '</li>'+ '<li v-if="cur!=all"><a v-on:click="cur++,pageClick()">下一頁(yè)</a></li>'+ '<li v-if="cur == all"><a class="banclick">下一頁(yè)</a></li>'+ '<li><a>共<i>{{all}}</i>頁(yè)</a></li>'+ '</ul>'+ '</div>'; var navBar = Vue.extend({ template:barHtml, props:['all','cur'], computed: { indexs: function(){ var left = 1; var right = this.all; var ar = []; if(this.all>= 5){ if(this.cur > 3 && this.cur < this.all-2){ left = this.cur - 2 right = this.cur + 2 }else{ if(this.cur<=3){ left = 1 right = 5 }else{ right = this.all left = this.all -4 } } } while (left <= right){ ar.push(left) left ++ } return ar } }, methods: { btnclick: function(data){ if(data != this.cur){ this.cur = data; this.$emit('btn-click',data); } }, pageClick: function(){ this.$emit('btn-click',this.cur); } }, }); window.pagenav = navBar;
這兒創(chuàng)建了一個(gè)全局的pagenav,可以在其它地方都可以調(diào)用。
html代碼
<div id="page"> <vue-nav :cur.sync="cur" :all.sync="all" v-on:btn-click="listenDate"></vue-nav> <p >{{msg}}</p> </div>
css代碼
.page-bar{ margin:40px; } ul,li{ margin: 0px; padding: 0px; } li{ list-style: none } .page-bar ul{ overflow: hidden; } .page-bar li{ float: left; } .page-bar li:first-child>a { margin-left: 0px } .page-bar a{ display: block; border: 1px solid #ddd; text-decoration: none; position: relative; padding: 6px 12px; margin-left: -1px; line-height: 1.42857143; color: #337ab7; cursor: pointer } .page-bar a:hover{ background-color: #eee; } .page-bar a.banclick{ cursor:not-allowed; } .page-bar .active a{ color: #fff; cursor: default; background-color: #337ab7; border-color: #337ab7; } .page-bar i{ font-style:normal; color: #d44950; margin: 0px 4px; font-size: 12px; }
新建一個(gè)vue對(duì)象實(shí)例
var pageBar = new Vue({ el: '#page', data: { all: 8, //總頁(yè)數(shù) cur: 1,//當(dāng)前頁(yè)碼 msg:'' }, components:{ 'vue-nav':pagenav }, watch: { cur: function(oldValue , newValue){ console.log('監(jiān)聽(tīng)cur前與后的值:'); console.log(arguments); } }, methods:{ listenDate:function(data){ this.cur = data; this.msg = '你點(diǎn)擊了'+data+ '頁(yè)'; } } })
簡(jiǎn)單的用js封裝了一下分頁(yè)組件。
實(shí)現(xiàn)效果
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <meta charset="utf-8"> <title></title> <meta name="keywords" content="" /> <meta name="description" content="" /> <script type="text/javascript" src="js/vue.min2.js"></script> <style> .page-bar{ margin:40px; } ul,li{ margin: 0px; padding: 0px; } li{ list-style: none } .page-bar ul{ overflow: hidden; } .page-bar li{ float: left; } .page-bar li:first-child>a { margin-left: 0px } .page-bar a{ display: block; border: 1px solid #ddd; text-decoration: none; position: relative; padding: 6px 12px; margin-left: -1px; line-height: 1.42857143; color: #337ab7; cursor: pointer } .page-bar a:hover{ background-color: #eee; } .page-bar a.banclick{ cursor:not-allowed; } .page-bar .active a{ color: #fff; cursor: default; background-color: #337ab7; border-color: #337ab7; } .page-bar i{ font-style:normal; color: #d44950; margin: 0px 4px; font-size: 12px; } </style> </head> <body> <div id="page"> <vue-nav :cur.sync="cur" :all.sync="all" v-on:btn-click="listenDate"></vue-nav> <p >{{msg}}</p> </div> <script type="text/javascript"> var barHtml = '<div class="page-bar">'+ '<ul>'+ '<li v-if="cur>1"><a v-on:click="cur--,pageClick()">上一頁(yè)</a></li>'+ '<li v-if="cur==1"><a class="banclick">上一頁(yè)</a></li>'+ '<li v-for="index in indexs" v-bind:class="{ active: cur == index}">'+ '<a v-on:click="btnclick(index)">{{ index }}</a>'+ '</li>'+ '<li v-if="cur!=all"><a v-on:click="cur++,pageClick()">下一頁(yè)</a></li>'+ '<li v-if="cur == all"><a class="banclick">下一頁(yè)</a></li>'+ '<li><a>共<i>{{all}}</i>頁(yè)</a></li>'+ '</ul>'+ '</div>'; var navBar = Vue.extend({ template:barHtml, props:['all','cur'], computed: { indexs: function(){ var left = 1; var right = this.all; var ar = []; if(this.all>= 5){ if(this.cur > 3 && this.cur < this.all-2){ left = this.cur - 2 right = this.cur + 2 }else{ if(this.cur<=3){ left = 1 right = 5 }else{ right = this.all left = this.all -4 } } } while (left <= right){ ar.push(left) left ++ } return ar } }, methods: { btnclick: function(data){ if(data != this.cur){ this.cur = data; this.$emit('btn-click',data); } }, pageClick: function(){ this.$emit('btn-click',this.cur); } }, }); window.pagenav = navBar; var pageBar = new Vue({ el: '#page', data: { all: 8, //總頁(yè)數(shù) cur: 1,//當(dāng)前頁(yè)碼 msg:'' }, components:{ 'vue-nav':pagenav }, watch: { cur: function(oldValue , newValue){ console.log('監(jiān)聽(tīng)cur前與后的值:'); console.log(arguments); } }, methods:{ listenDate:function(data){ this.cur = data; this.msg = '你點(diǎn)擊了'+data+ '頁(yè)'; } } }) </script> </body> </html>
以上是“vuejs2.0如何實(shí)現(xiàn)分頁(yè)組件”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
本文標(biāo)題:vuejs2.0如何實(shí)現(xiàn)分頁(yè)組件
瀏覽路徑:http://www.rwnh.cn/article0/pgsgio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、企業(yè)網(wǎng)站制作、軟件開(kāi)發(fā)、面包屑導(dǎo)航、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)