本文實(shí)例為大家分享了Vue實(shí)現(xiàn)web分頁(yè)組件的具體代碼,供大家參考,具體內(nèi)容如下
創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),博白企業(yè)網(wǎng)站建設(shè),博白品牌網(wǎng)站建設(shè),網(wǎng)站定制,博白網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,博白網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。效果演示

源代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>測(cè)試分頁(yè) - www.maoyupeng.com</title>
<style type="text/css">
body{padding:0; margin: 0; broder:none; } #app {width: 500px; height: 200px; margin: 0 auto; text-align: center; background-color: #cccccc; } #mylink {color: #efefef; } .pagination{list-style: none; text-align: center; height: 50px; padding-top: 50px; } .pagination > li {float: left; margin: 0 5px; } [v-cloak] {display: none; } </style>
</head>
<body>
<div id="app" v-cloak>
<ul class="pagination">
<li>
<a v-if="currentPage == 1" >首頁(yè)</a>
<a v-else href="javascript:;" @click="next(1)">首頁(yè)</a>
</li>
<li v-if="currentPage<=1"><a>上一頁(yè)</a></li>
<li v-else><a href="javascript:;" @click="next(currentPage-1)">上一頁(yè)</a></li>
<li v-for="item in pagingList">
<a v-if="currentPage==item.key || sign ==item.key" >{{item.key}}</a>
<a v-else href="javascript:;" @click="next(item.value)">{{item.key}}</a>
</li>
<li v-if="currentPage>=totalPageCount"><a>下一頁(yè)</a></li>
<li v-else><a href="javascript:;" @click="next(currentPage+1)">下一頁(yè)</a></li>
<li>
<a v-if="totalPageCount == currentPage">尾頁(yè)</a>
<a v-else href="javascript:;" @click="next(totalPageCount)">尾頁(yè)</a>
</li>
</ul>
<p>共:{{totalPageCount||0}}頁(yè),當(dāng)前頁(yè)為第{{currentPage||0}}頁(yè) 設(shè)置總頁(yè)數(shù):<input v-model="totalPageCount"></p>
<a target="_blank" id="mylink">http://www.maoyupeng.com 帶注解版本</a>
</div>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
// 省略的符號(hào)
sign:'...',
// 省略號(hào)位置
signIndex:4,
// 總頁(yè)數(shù)
totalPageCount: 4,
// 當(dāng)前頁(yè)
currentPage:1,
// 顯示在頁(yè)面的數(shù)組列表
pagingList:[]
},
watch: {
totalPageCount (val) {
var that = this
if (!val || val == '') return;
that.currentPage = 1;
that.init()
},
currentPage (val) {
var that = this
that.init()
}
},
methods: {
// 跳轉(zhuǎn)到某頁(yè)碼
next (num) {
var that = this
if (num <= 1) that.currentPage = 1;
else if (num >= that.totalPageCount) that.currentPage = that.totalPageCount;
else that.currentPage = num;
},
// 初始化數(shù)據(jù)
fetchData () {
var that = this
that.pagingList = [];
var tmp = null;
if ((that.totalPageCount) > 6) {
if (((that.totalPageCount-1) == (that.totalPageCount - that.currentPage)) && (that.totalPageCount - that.currentPage) > 5) {
for (var i=1;i<7;i++) {
if (i < that.signIndex) {
tmp = {key:i, value:i }
} else if (i== that.signIndex) {
tmp = {key:that.sign, value:0 }
} else if (i == (that.signIndex + 1) ) {
tmp = {key:that.totalPageCount - 1, value:that.totalPageCount - 1 }
} else {
tmp = {key:that.totalPageCount, value:that.totalPageCount }
}
that.pagingList.push(tmp)
}
} else if (((that.totalPageCount - that.currentPage) <= that.signIndex)){
var starNum = that.totalPageCount - 5;
for (var i=starNum;i<starNum+6;i++) {
tmp = {key:i, value:i }
that.pagingList.push(tmp)
}
} else {
var starNum = that.currentPage - 1;
for (var i=1;i<7;i++) {
if (i < that.signIndex) {
tmp = {key:(starNum - 1) + i, value:(starNum - 1) + i }
} else if (i== that.signIndex) {
tmp = {key:that.sign, value:0 }
} else if (i == (that.signIndex + 1) ) {
tmp = {key:that.totalPageCount - 1, value:that.totalPageCount - 1 }
} else {
tmp = {key:that.totalPageCount, value:that.totalPageCount }
}
that.pagingList.push(tmp)
}
}
} else {
for (var i =0; i <that.totalPageCount; i++) {
tmp = {key:i+1, value:i+1 }
that.pagingList.push(tmp)
}
}
},
init () {
var that = this
that.fetchData()
}
},
mounted () {
var that = this
that.init()
}
})
</script>
</body>
</html>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前標(biāo)題:Vue實(shí)現(xiàn)web分頁(yè)組件詳解-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://chinadenli.net/article20/ceghjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、電子商務(wù)、網(wǎng)站策劃、網(wǎng)站制作、服務(wù)器托管、網(wǎng)頁(yè)設(shè)計(jì)公司
聲明:本網(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í)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容