vue實現(xiàn)一個簡單的分頁功能實例詳解
這是一個簡單的分頁功能,只能夠前端使用,數(shù)據(jù)不能通過后臺服務(wù)器進行更改,能容已經(jīng)寫死了。
下面的內(nèi)容我是在做一個關(guān)于婚紗項目中用到的,當(dāng)時好久沒用vue了,就上網(wǎng)區(qū)找了別人的博客來看,發(fā)現(xiàn)只有關(guān)于element_ui的,基本全是,對自己沒用什么用,就自己寫了一個,效果如下:
點擊相應(yīng)的按鈕切換到對應(yīng)的內(nèi)容內(nèi)容:
下面我只發(fā)核心代碼,css樣式就不發(fā)了,自己想怎么寫怎么寫
<!-- 分頁內(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> <!-- 分頁按鈕組 --> <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代碼可能有點多,但是沒關(guān)系,這個會了,以后遇到直接就可以拿來用了
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' }], // 控制每頁顯示數(shù)據(jù)的數(shù)數(shù)量 pageSize: 3, // 默認顯示第幾頁 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實現(xiàn)一個簡單的分頁功能的詳細內(nèi)容,更多關(guān)于vue實現(xiàn)一個簡單的分頁功能的資料請關(guān)注腳本之家其它相關(guān)文章!
- vuejs實現(xiàn)本地數(shù)據(jù)的篩選分頁功能思路詳解
- Vue2.5 結(jié)合 Element UI 之 Table 和 Pagination 組件實現(xiàn)分頁功能
- Vue+element-ui 實現(xiàn)表格的分頁功能示例
- vue+vuex+json-seiver實現(xiàn)數(shù)據(jù)展示+分頁功能
- vue實現(xiàn)的上拉加載更多數(shù)據(jù)/分頁功能示例
- vue+elementUI組件table實現(xiàn)前端分頁功能
- vue實現(xiàn)分頁功能
- vue實現(xiàn)表格分頁功能
- vue實現(xiàn)簡單分頁功能
- vue實現(xiàn)簡單的分頁功能
- vue iview實現(xiàn)分頁功能
相關(guān)文章
Vue/React子組件實例暴露方法(TypeScript)
最近幾個月都在用TS開發(fā)各種項目,框架有涉及到Vue3,React18等,記錄一下Vue/React組件暴露出變量/函數(shù)的方法的寫法,對vue?react組件暴露方法相關(guān)知識感興趣的朋友跟隨小編一起看看吧2022-11-11Vue如何整合mavon-editor編輯器(markdown編輯和預(yù)覽)
這篇文章主要介紹了Vue整合mavon-editor編輯器(markdown編輯和預(yù)覽)的相關(guān)知識,mavon-editor是目前比較主流的markdown編輯器,重點介紹它的使用方法,需要的朋友可以參考下2022-10-10表格Table實現(xiàn)前端全選所有功能方案示例(包含非當(dāng)前頁)
這篇文章主要為大家介紹了表格Table實現(xiàn)前端全選所有功能,包括非當(dāng)前頁的方案示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2024-02-02Vue前端數(shù)值轉(zhuǎn)換為千分位格式并保留兩位小數(shù)代碼示例
在Vue.js開發(fā)中我們經(jīng)常會遇到需要將數(shù)字格式化為保留兩位小數(shù)的情況,下面這篇文章主要給大家介紹了關(guān)于Vue前端數(shù)值轉(zhuǎn)換為千分位格式并保留兩位小數(shù)的相關(guān)資料,需要的朋友可以參考下2024-06-06vue項目環(huán)境搭建?啟動?移植操作示例及目錄結(jié)構(gòu)分析
這篇文章主要介紹了vue項目環(huán)境搭建、啟動、項目移植、項目目錄結(jié)構(gòu)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步早日升職加薪2022-04-04