DDR爱好者之家 Design By 杰米
不废话,先上组件文件pages.vue:
<template> <div class="pages-box" v-if="pageTotal > 0"> <ul class="pages"> <li class="pages-prev"> <a v-if="pageNow != 1" href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" @click="prevClick">上一页</a> </li> <!--如果只有一页就不显示固定的第一个分页按钮了,避免重复--> <template v-if="pageTotal > 1"> <li v-for="i in pageBegin" class="pages-li" :class="{active:i == pageNow}"> <span v-if="i == pageNow" v-text="i"></span> <a v-else href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" @click="pageClick" v-text="i"></a> </li> </template> <li v-if="ellipsis[0] > slider"> <span>...</span> </li> <li v-for="i in pageMiddle" class="pages-li" :class="{active:i == pageNow}"> <span v-if="i == pageNow" v-text="i"></span> <a v-else href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" @click="pageClick" v-text="i"></a> </li> <li v-if="pageTotal - ellipsis[1] > slider"> <span>...</span> </li> <li v-for="i in pageEnd" class="pages-li" :class="{active:i == pageNow}"> <span v-if="i == pageNow" v-text="i"></span> <a v-else href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" @click="pageClick" v-text="i"></a> </li> <li class="pages-next"> <a v-if="pageNow != pageTotal" href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" @click="nextClick">下一页</a> </li> </ul> </div> </template> <script> export default{ name: 'pages', props: { //总页数 total: { type: [Number, String], required: true }, //当前页 now: { type: [Number, String], default: 1 } }, data() { return { //当前页 pageNow: this.now, //总页数 pageTotal: this.total, //输入的页码 pageNum: "", //显示分页按钮的个数 length: 8, //前后固定的分页按钮个数 slider: 1 } }, watch: { total(val){ let page_total = parseInt(val); page_total = (isNaN(page_total) || page_total < 1) ""; this.changePage(this.pageNow); }, // 切换分页 changePage(page){ let {name, params, query} = this.$route; this.$router.push({ name, params: Object.assign(params, {page}), query }); } } } </script> <style lang="sass" type="text/scss" rel="stylesheet/scss"> @import '../scss/base/variables'; .pages-box{ position: relative; padding: 5px 10px; margin: 20px 0; text-align: center; } .pages{ display: inline-block; padding: 10px 0; &:after{ content: ""; display: table; line-height: 0; clear: both; } li{ float: left; height: 20px; line-height: 20px; text-align: center; margin: 0 2px; box-sizing: border-box; font-size: 13px; span, a{ display: block; width: 100%; height: 100%; padding: 0 2px; box-sizing: border-box; } } .pages-li{ min-width: 30px; border: 1px solid $theme; color: $theme; a{ color: $theme; } &.active{ span{ background: $theme; color: #fff; } } } .pages-prev, .pages-next{ padding: 0 8px; font-size: 12px; a{ display: block; height: 100%; position: relative; color: $theme; &:before{ content: ''; position: absolute; top: 50%; display: block; width: 6px; height: 6px;margin-top:-4px; border-left: 1px solid $theme; border-top: 1px solid $theme; } } } .pages-prev a{ padding-left: 8px; &:before{ transform:rotate(-45deg); left: 0; } } .pages-next a{ padding-right: 8px; &:before{ transform:rotate(135deg); right: 0; } } .pages-num{ .num-input{ min-width: 20px; height: 20px; padding: 0 5px; line-height: 20px; border-radius: 2px; border: 1px solid $theme; color: $theme; text-align: center; outline: none; } } .pages-go{ a{ color: $theme; } span{ color: #666; } } } </style>
使用方法:
在需要分页的地方使用分页组件标签,比如这里的order.vue:
<!--分页组件--> <pages :now="page" :total="totalPage" v-if="totalPage > 0"></pages>
在data中设置当前页和总页面的默认值
data(){ return { totalPage:1, page:1, } },
考虑一下我们希望我们点击页数按钮后发生什么
首先,点击某页数时路由会改变页数,从路由获取当前页
this.page = this.$route.params.page;
接着,我们希望有一个getorderfromServer方法将当前页数发送给服务器,再将返回的数据更新在页面上
getorderfromServer({ currentPage:this.page })
最后调用的方法:
methods: { // 查询全部订单 getorderfromServer(){ this.loading = true; this.page = this.$route.params.page; getorderfromServer({ currentPage: this.page, orderTimeStart:this.orderTimeStart, orderTimeEnd:this.orderTimeEnd, serviceName:this.serviceName, shopName:this.shopName, status: this.status }).then(({code, data}) => { if (code == 200) { this.Orderlist = data.list; this.totalPage = data.totalPage; } this.loading = false; }).catch(err => { this.tip('服务内部错误', 'error'); this.Orderlist = {}; this.loading = false; }); }, }
注意通过路由对方法作出响应,每次路由改变都调用此方法以更新页面
watch: { $route: 'getorderfromServer' }
还要对路由信息进行改造,让每一页(尤其是第一页)都有路由页数信息,可以对第一页进行重定向以达到目的:
{ path: 'order', redirect: 'order/page/1', }, { path: 'order/page/:page', component(resolve){ require.ensure([], function (require) { resolve(require('../modules/personal/order/myorder.vue')); }, 'modules/personal') }, name:'order', meta: { login: 'none' } },
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月27日
2024年11月27日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]