vue實現(xiàn)分頁組件
更新時間:2020年06月16日 14:50:40 作者:anshengsuiyeu
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)分頁組件的具體代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(xiàn)分頁組件的具體代碼,供大家參考,具體內(nèi)容如下
<template>
<div class="pageBox">
<ul>
<li v-if="this.condition.pageNo > 1 && this.pages.length > 4" class="sides"><a @click="prePage()"><s class="font_main"></s></a></li>
<li v-for="(item, index) in pages" :class="{'curtPage': condition.pageNo == item}">
<a v-if="item" @click="goPage(item)" >
<s>{{item}}</s>
</a>
<a href="javascript:;" rel="external nofollow" v-else>...</a>
</li>
<li class="sides" v-if="condition.pageNo < pageCount && this.pageCount > 4"><a @click="nextPage()"><s class="font_main"></s></a></li>
</ul>
</div>
</template>
js中代碼 page 和condition是由父組件中傳過來的參數(shù)
<script>
export default {
props: {
page: Object,
condition: Object
},
data () {
return {
pageSize: this.condition.pageSize
}
},
computed: {
pageCount: function () {
return this.page.totalCount / this.condition.pageSize > 0 ? this.page.totalCount % this.condition.pageSize === 0 ? this.page.totalCount / this.condition.pageSize : Math.ceil(this.page.totalCount / this.condition.pageSize) : 1
},
pages () {
let c = this.condition.pageNo
let t = this.pageCount
let arr = []
if (t === 1) {
return arr
}
if (t <= 4) {
for (let i = 1; i <= t; i++) {
arr.push(i)
}
return arr
}
if (c <= 3) return [1, 2, 3, 0, t]
if (c >= t - 1) return [1, 0, t - 2, t - 1, t]
// if (c === 4) return [1, 2, 3, 4, 5, 0, t]
// if (c === (t - 2)) return [1, 0, t - 3, t - 2, t - 1, t]
return [1, 0, c - 1, c, c + 1, 0, t]
}
},
methods: {
goPage (indexPage) {
if (this.indexPage !== this.condition.pageNo) {
this.condition.pageNo = indexPage
this.$emit('search')
}
},
prePage () {
if (this.condition.pageNo !== 1) {
this.condition.pageNo--
this.goPage(this.condition.pageNo)
}
},
nextPage () {
if (this.condition.pageNo !== this.pageCount) {
this.condition.pageNo++
this.goPage(this.condition.pageNo)
}
}
}
}
</script>
效果圖:



以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue CLI3創(chuàng)建項目部署到Tomcat 使用ngrok映射到外網(wǎng)
這篇文章主要介紹了Vue CLI3創(chuàng)建項目部署到Tomcat 使用ngrok映射到外網(wǎng),本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-05-05
Vue3 響應(yīng)式高階用法之triggerRef()的使用
在Vue3響應(yīng)式系統(tǒng)中,shallowRef僅追蹤頂層屬性的變化,當(dāng)需要對內(nèi)層屬性作出反應(yīng)時,可使用triggerRef()方法手動觸發(fā)更新,本文介紹了triggerRef()的應(yīng)用場景、基本用法、功能和最佳實踐,感興趣的可以了解一下2024-09-09
vue之a(chǎn)-table中實現(xiàn)清空選中的數(shù)據(jù)
今天小編就為大家分享一篇vue之a(chǎn)-table中實現(xiàn)清空選中的數(shù)據(jù),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
vue中利用simplemde實現(xiàn)markdown編輯器(增加圖片上傳功能)
這篇文章主要介紹了vue中利用simplemde實現(xiàn)markdown編輯器(增加圖片上傳功能),本文通過實例代碼相結(jié)合的形式給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-04-04

