vue實(shí)現(xiàn)分頁組件
更新時(shí)間:2020年06月16日 14:50:40 作者:anshengsuiyeu
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)分頁組件的具體代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了vue實(shí)現(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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue基于Teleport實(shí)現(xiàn)Modal組件
Teleport 提供了一種干凈的方法,允許我們控制在 DOM 中哪個(gè)父節(jié)點(diǎn)下渲染了 HTML,而不必求助于全局狀態(tài)或?qū)⑵洳鸱譃閮蓚€(gè)組件。2021-05-05Vue?element-ui表格內(nèi)嵌進(jìn)度條功能實(shí)現(xiàn)方法
Element-Ul是餓了么前端團(tuán)隊(duì)推出的一款基于Vue.js 2.0 的桌面端UI框架,下面這篇文章主要給大家介紹了關(guān)于Vue?element-ui表格內(nèi)嵌進(jìn)度條功能的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03解決vue打包 npm run build-test突然不動(dòng)了的問題
這篇文章主要介紹了解決vue打包 npm run build-test突然不動(dòng)了的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-11-11Vue實(shí)現(xiàn)導(dǎo)出Excel表格文件提示“文件已損壞無法打開”的解決方法
xlsx用于讀取解析和寫入Excel文件的JavaScript庫,它提供了一系列的API處理Excel文件,使用該庫,可以將數(shù)據(jù)轉(zhuǎn)換Excel文件并下載到本地,適用于在前端直接生成Excel文件,這篇文章主要介紹了Vue實(shí)現(xiàn)導(dǎo)出Excel表格,提示文件已損壞,無法打開的解決方法,需要的朋友可以參考下2024-01-01