日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > vue >内容正文

vue

vue实现分页组件

發(fā)布時(shí)間:2023/12/31 vue 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue实现分页组件 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

vue實(shí)現(xiàn)分頁(yè)組件

創(chuàng)建pagination.vue

/** 所需參數(shù)* total Number 總頁(yè)數(shù)* current Number 當(dāng)前頁(yè)面下標(biāo)* pageSize Number 頁(yè)面顯示條數(shù)* sizes Array 頁(yè)面條數(shù)容器數(shù)組* jump(index) function 重新獲取數(shù)據(jù)的方法* getPageSize(index) function 更改頁(yè)面顯示條數(shù)的方法*/ <style lang="less">@color:#1199F0;.page-wrapper{padding:20px 10px;ul{overflow: hidden;display: table;margin: 0 auto;height: 50px;list-style: none;li{float:left;}}.paging-size{height:30px;margin-right:20px;select{width:50px;height:30px;text-align:center;border:1px solid @color;}}.paging-item{height: 30px;line-height: 30px;margin: 3px;padding-left:12px;padding-right:12px;border-radius: 5px;font-size: 12px;color: #666;cursor: pointer;&:hover,&.current{color:#fff;background-color: @color;}}.paging-jump{margin-left:20px;margin-top:3px;height:30px;font-size:0;overflow: hidden;input[type="number"]{float: left;padding:0 5px;width:50px;height:28px;text-align:center;border:1px solid @color;}input[type="button"]{float: left;padding:0 12px;height:30px;border:none;color:#fff;background-color: @color;}}} </style> <template><div class="page-wrapper"><ul><li class="paging-size"><select @change="getPageSize"><option v-for="i in sizes" :value="i" :selected="i==pageSize">{{i}}</option></select></li><li class="paging-item" v-if="current!=1" @click='jump(1)'>首頁(yè)</li><li class="paging-item" v-if="current-1>0" @click='jump(current-1)'>上一頁(yè)</li><li class="paging-item" v-if="current-2>0" @click='jump(current-2)'>{{current-2}}</li><li class="paging-item" v-if="current-1>0" @click='jump(current-1)'>{{current-1}}</li><li class="paging-item current" @click='jump(current)'>{{current}}</li><li class="paging-item" v-if="total-current>1" @click='jump(current+1)'>{{current+1}}</li><li class="paging-item" v-if="total-current>2" @click='jump(current+2)'>{{current+2}}</li><li class="paging-item" v-if="total-current>1" @click='jump(current+1)'>下一頁(yè)</li><li class="paging-item" v-if="current!=total" @click='jump(total)'>尾頁(yè)</li><li class="paging-jump"><input type="number" v-model="jumpPage" :max="total" min="0"/><input type="button" value="跳轉(zhuǎn)" @click='jump(jumpPage)'/></li></ul></div> </template> <script>export default {data(){return {jumpPage:0}},props:{total:Number,current:Number,pageSize:Number,sizes:{type:Array,default:function(){return [15,25,35]}}},mounted(){if(this.total-this.current>1){this.jumpPage=this.current+1;}else{this.jumpPage=1;}},watch:{current(){if(this.total-this.current>1){this.jumpPage=this.current+1;}else{this.jumpPage=1;}}},methods:{jump(index){index=Number(index);if (this.current != index && index > 0 && index < this.total + 1) {this.$emit('jump', index);}},getPageSize(e){let pageSize=Number(e.target.value);this.$emit('getPageSize',pageSize);}}} </script>

index.vue中注冊(cè)

components:{'v-pagination':(resolve)=>{require(['components/pagination'],resolve);}}

index.vue中使用

<v-pagination:total="total":current="current":pageSize="pageSize"@getPageSize="getPageSize"@jump="jump"></v-pagination>

完整index.vue代碼

<template><div class="wrapper" v-swipeleft='left' v-swiperight='right'><v-pagination:total="total":current="current":pageSize="pageSize"@getPageSize="getPageSize"@jump="jump"></v-pagination></div> </template><script> export default {data () {return {total:20,current:4,pageSize:25}},methods:{jump(index){this.current=index;},getPageSize(pageSize){this.pageSize=pageSize;}},components:{'v-pagination':(resolve)=>{require(['components/pagination'],resolve);}} } </script> <style lang="less" scoped="scoped"> .wrapper{height:100%;width:100%; } </style>

總結(jié)

以上是生活随笔為你收集整理的vue实现分页组件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。