vue實(shí)現(xiàn)一個(gè)簡(jiǎn)單的分頁(yè)功能實(shí)例詳解
這是一個(gè)簡(jiǎn)單的分頁(yè)功能,只能夠前端使用,數(shù)據(jù)不能通過(guò)后臺(tái)服務(wù)器進(jìn)行更改,能容已經(jīng)寫(xiě)死了。
下面的內(nèi)容我是在做一個(gè)關(guān)于婚紗項(xiàng)目中用到的,當(dāng)時(shí)好久沒(méi)用vue了,就上網(wǎng)區(qū)找了別人的博客來(lái)看,發(fā)現(xiàn)只有關(guān)于element_ui的,基本全是,對(duì)自己沒(méi)用什么用,就自己寫(xiě)了一個(gè),效果如下:
點(diǎn)擊相應(yīng)的按鈕切換到對(duì)應(yīng)的內(nèi)容內(nèi)容:
下面我只發(fā)核心代碼,css樣式就不發(fā)了,自己想怎么寫(xiě)怎么寫(xiě)
<!-- 分頁(yè)內(nèi)容 --> <ul class="blog-lists-box"> <li class="blog-list" :key="index" v-for="(item, index) in dataShow" :class="{ 'alt': index%2 == 1 }"> <div class="card"> <div class="blog-overlay"> <router-link to="/blog/singleBlog"> <figure> <img :src="img1"/> <figcaption></figcaption> </figure> </router-link> </div> <div class="card-body"> <router-link to="/blog/singleBlog"> <h4 class="card-title">{{item.title}}</h4> </router-link> <div class="card-footer"> <div class="card-footer-box d-flex"> <div class="author-box"> <a href="#" rel="external nofollow" > <img :src="header1"/> <span>{{item.username}}</span> </a> </div> <div class="blog-date text-uppercase"> <i class="fa fa-calendar"></i> <span>{{item.time}}</span> </div> </div> </div> </div> </div> </li> </ul> <!-- 分頁(yè)按鈕組 --> <div class="page"> <ul class="pagination clearfix flex-center"> <li class="page-item stic"> <a class="page-link " v-on:click="prePage">Prev</a> </li> <li class="page-item" :key="index" v-for="(item, index) in totalPage"> <a class="page-link" v-on:click="toPage(index)" :class="{active: currentPage == index}">{{ index+1 }}</a> </li> <li class="page-item"> <a class="page-link" v-on:click="nextPage">Next</a> </li> </ul> </div>
下面是vuejs代碼可能有點(diǎn)多,但是沒(méi)關(guān)系,這個(gè)會(huì)了,以后遇到直接就可以拿來(lái)用了
data () { return { img1: img1, header1: header1, listArray: [{ 'title': '25 Places To Get The Best Wedding...', 'username': 'liulong', 'time': '2019/12/6' }, { 'title': '10 Bridal Bouquets You'll Fall In Love...', 'username': 'wangxianhui', 'time': '2019/12/7' }, { 'title': 'Tips For Choosing The Right Weddi...', 'username': 'chenggang', 'time': '2019/12/8' }, { 'title': 'Planning The Perfect Bachelorette...', 'username': 'wangwengang', 'time': '2019/12/9' }, { 'title': 'Top 20 Tips for Wedding Invitat...', 'username': 'yuzhiwei', 'time': '2019/12/10' }, { 'title': 'Best Tips for the Bride and Groom...', 'username': 'zhaopu', 'time': '2019/12/11' }], // 控制每頁(yè)顯示數(shù)據(jù)的數(shù)數(shù)量 pageSize: 3, // 默認(rèn)顯示第幾頁(yè) currentPage: 0, // 總數(shù)據(jù) totalPage: [], // 當(dāng)前顯示的數(shù)據(jù) dataShow: [] } }, methods: { nextPage: function () { if (this.currentPage === this.pageNum - 1) { return } this.dataShow = this.totalPage[++this.currentPage] }, prePage: function () { if (this.currentPage === 0) { return } this.dataShow = this.totalPage[--this.currentPage] }, toPage: function (page) { this.currentPage = page this.dataShow = this.totalPage[this.currentPage] } }, created: function () { this.pageNum = Math.ceil(this.listArray.length / this.pageSize) || 1 for (var i = 0; i < this.pageNum; i++) { this.totalPage[i] = this.listArray.slice(this.pageSize * i, this.pageSize * (i + 1)) } this.dataShow = this.totalPage[this.currentPage] }
以上就是vue實(shí)現(xiàn)一個(gè)簡(jiǎn)單的分頁(yè)功能的詳細(xì)內(nèi)容,更多關(guān)于vue實(shí)現(xiàn)一個(gè)簡(jiǎn)單的分頁(yè)功能的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- vuejs實(shí)現(xiàn)本地?cái)?shù)據(jù)的篩選分頁(yè)功能思路詳解
- Vue2.5 結(jié)合 Element UI 之 Table 和 Pagination 組件實(shí)現(xiàn)分頁(yè)功能
- Vue+element-ui 實(shí)現(xiàn)表格的分頁(yè)功能示例
- vue+vuex+json-seiver實(shí)現(xiàn)數(shù)據(jù)展示+分頁(yè)功能
- vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁(yè)功能示例
- vue+elementUI組件table實(shí)現(xiàn)前端分頁(yè)功能
- vue實(shí)現(xiàn)分頁(yè)功能
- vue實(shí)現(xiàn)表格分頁(yè)功能
- vue實(shí)現(xiàn)簡(jiǎn)單分頁(yè)功能
- vue實(shí)現(xiàn)簡(jiǎn)單的分頁(yè)功能
- vue iview實(shí)現(xiàn)分頁(yè)功能
相關(guān)文章
Vue/React子組件實(shí)例暴露方法(TypeScript)
最近幾個(gè)月都在用TS開(kāi)發(fā)各種項(xiàng)目,框架有涉及到Vue3,React18等,記錄一下Vue/React組件暴露出變量/函數(shù)的方法的寫(xiě)法,對(duì)vue?react組件暴露方法相關(guān)知識(shí)感興趣的朋友跟隨小編一起看看吧2022-11-11Vue如何整合mavon-editor編輯器(markdown編輯和預(yù)覽)
這篇文章主要介紹了Vue整合mavon-editor編輯器(markdown編輯和預(yù)覽)的相關(guān)知識(shí),mavon-editor是目前比較主流的markdown編輯器,重點(diǎn)介紹它的使用方法,需要的朋友可以參考下2022-10-10表格Table實(shí)現(xiàn)前端全選所有功能方案示例(包含非當(dāng)前頁(yè))
這篇文章主要為大家介紹了表格Table實(shí)現(xiàn)前端全選所有功能,包括非當(dāng)前頁(yè)的方案示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-02-02解決Vue router-link綁定事件不生效的問(wèn)題
這篇文章主要介紹了解決Vue router-link綁定事件不生效的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07Vue前端數(shù)值轉(zhuǎn)換為千分位格式并保留兩位小數(shù)代碼示例
在Vue.js開(kāi)發(fā)中我們經(jīng)常會(huì)遇到需要將數(shù)字格式化為保留兩位小數(shù)的情況,下面這篇文章主要給大家介紹了關(guān)于Vue前端數(shù)值轉(zhuǎn)換為千分位格式并保留兩位小數(shù)的相關(guān)資料,需要的朋友可以參考下2024-06-06Antd中單個(gè)DatePicker限定時(shí)間輸入范圍操作
這篇文章主要介紹了Antd中單個(gè)DatePicker限定時(shí)間輸入范圍操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10vue.js封裝switch開(kāi)關(guān)組件的操作
這篇文章主要介紹了vue.js封裝switch開(kāi)關(guān)組件的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10vue項(xiàng)目環(huán)境搭建?啟動(dòng)?移植操作示例及目錄結(jié)構(gòu)分析
這篇文章主要介紹了vue項(xiàng)目環(huán)境搭建、啟動(dòng)、項(xiàng)目移植、項(xiàng)目目錄結(jié)構(gòu)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2022-04-04