這篇文章將為大家詳細(xì)講解有關(guān)Vue如何實(shí)現(xiàn)簡(jiǎn)易翻頁(yè)效果,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的昌樂(lè)網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!為什么要使用VueVue是一款友好的、多用途且高性能的JavaScript框架,使用vue可以創(chuàng)建可維護(hù)性和可測(cè)試性更強(qiáng)的代碼庫(kù),Vue允許可以將一個(gè)網(wǎng)頁(yè)分割成可復(fù)用的組件,每個(gè)組件都包含屬于自己的HTML、CSS、JavaScript,以用來(lái)渲染網(wǎng)頁(yè)中相應(yīng)的地方,所以越來(lái)越多的前端開(kāi)發(fā)者使用vue。
源碼如下:
<html> <head> <meta charset="UTF-8"> <title>slidePage</title> <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script> <style type="text/css"> *{ margin: 0; padding: 0; } .container { width: 100%; margin: 0 auto; text-align: center; } .content{ font-size: 400px } .leftBtn{ width: 45px; height: 45px; margin-right: 15px; } .rightBtn{ width: 45px; height: 45px; margin-left: 15px; } </style> </head> <body> <div id='root'> <div v-if="numberArr.length == 0">{{showMessage}}</div> <div class="container" v-for="(item, index) in getCurPageContent(numberArr, curPage, itemNumPerPage)" :key="index"> <div class="content">{{item}}</div> <div class="pageButtonList"> <button class="leftBtn" @click="handleClick('leftBtn')"><</button> <span class="pagination">{{curPage}}/{{totalPage}}</span> <button class="rightBtn" @click="handleClick('rightBtn')">></button> </div> </div> </div> <script> new Vue({ el: "#root", data(){ return { showMessage: 'No number', content:'', numberArr: [1, 2, 3, 4], curPage: 1, totalPage: 1, itemNumPerPage: 1 } }, mounted() { this.init() }, methods:{ init(){ this.totalPage = Math.ceil(this.numberArr.length / this.itemNumPerPage) this.totalPage = this.totalPage < 1 ? 1 : this.totalPage }, getCurPageContent: function(numberArr, curPage, itemNumPerPage){ return numberArr.filter(function(element, index){ if(index >= (curPage -1)* itemNumPerPage && index < curPage *itemNumPerPage){ return true }else{ return false } }) }, handleClick: function(arg){ if(arg == 'leftBtn'){ this.curPage = this.curPage > 1 ? --this.curPage : this.totalPage }else if (arg == 'rightBtn'){ this.curPage = this.curPage < this.totalPage ? ++this.curPage: 1 } } // handleLeftClick: function(){ // if(this.curPage > 1){ // this.curPage -- // }else{ // this.curPage = this.totalPage // } // }, // handleRightClick: function(){ // if(this.curPage < this.totalPage){ // this.curPage ++ // }else{ // this.curPage = 1 // } // } } }) </script> </body> </html>
效果如下所示,點(diǎn)擊左右能切換頁(yè)面:
關(guān)于“Vue如何實(shí)現(xiàn)簡(jiǎn)易翻頁(yè)效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
網(wǎng)站題目:Vue如何實(shí)現(xiàn)簡(jiǎn)易翻頁(yè)效果-創(chuàng)新互聯(lián)
鏈接URL:http://bm7419.com/article4/ddpjoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、網(wǎng)站導(dǎo)航、微信小程序、標(biāo)簽優(yōu)化、面包屑導(dǎo)航、移動(dòng)網(wǎng)站建設(shè)
聲明:本網(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)
猜你還喜歡下面的內(nèi)容