vue實現(xiàn)一個簡單的分頁功能實例詳解
這是一個簡單的分頁功能,只能夠前端使用,數(shù)據(jù)不能通過后臺服務(wù)器進(jìn)行更改,能容已經(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,
// 默認(rèn)顯示第幾頁
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)一個簡單的分頁功能的詳細(xì)內(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實現(xiàn).md文件預(yù)覽功能的兩種方法詳解
這篇文章主要介紹了Vue預(yù)覽.md文件的兩種方法,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2025-04-04
在vue-cli 3中給stylus、sass樣式傳入共享的全局變量
這篇文章主要介紹了在vue-cli 3中, 給stylus、sass樣式傳入共享的全局變量,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08
關(guān)于Vue3中element-plus的el-dialog對話框無法顯示的問題及解決方法
最近今天在寫一個停車場管理系統(tǒng)的項目時,在用vue3寫前端時,在前端模板選擇上,我一時腦抽,突然決定放棄SpringBoot,選擇了以前幾乎很少用的element-plus,然后果不其然,錯誤連連,下面給大家分享dialog對話框無法顯示的原因,感興趣的朋友一起看看吧2023-10-10
vue點擊按鈕動態(tài)創(chuàng)建與刪除組件功能
這篇文章主要介紹了vue點擊按鈕動態(tài)創(chuàng)建與刪除組件功能,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12
復(fù)刻畫龍產(chǎn)品vue實現(xiàn)新春氣泡兔
這篇文章主要為大家介紹了復(fù)刻畫龍產(chǎn)品之使用vue實現(xiàn)新春氣泡兔示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01

