vue实现分页组件
程序员文章站
2022-06-21 08:25:24
本文实例为大家分享了vue实现分页组件的具体代码,供大家参考,具体内容如下
本文实例为大家分享了vue实现分页组件的具体代码,供大家参考,具体内容如下
<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是由父组件中传过来的参数
<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>
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: Apache 开通子站点配置方法
下一篇: 韭菜产妇可以吃吗