不懂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>
效果图:
感谢你能够认真阅读完这篇文章,希望小编分享vue实现分页组件的源代码是什么?内容对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。