vue使用element-ui 实现自定义分页

element-ui文档截图,plus大同小异。
在这里插入图片描述
可以通过插槽实现自定义的分页。在layout里面进行配置。
在这里插入图片描述

全部代码

//page.js
export default {
	name:Cuspage,
	props:{
		total:Number,
	},
	data(){
		return {
			currentPage:1,
			pageSize:10,
		}
	}
	methods: {
		setslot (h) {
			return(
				<div class="cusPage"<span on-click={this.toBegin}>首页く/span>
					<span on-click={this.toPre}>上一页く/Span>
					<span on-click={this.tovext}>下一页</span>
					<span on-click={this.toEnd}>未页く/span>
					<span>{this.currentPage}/{this.alltotal}</span>
				</div>
			)
		 },
		 toEnd(){
		 	this.$emit('current-change',this.allPage);
		 	this.currentPage = this.allPage;
		 },
		 toBegin() {
		 	this.$emit('current-change',1);
		 	this.currentPage = 1;
		 }
		 toNext() {
		 	ifthis.$refs.cusPage){
		 		this.$refs.cusPage.next()
		 	}
		 },
		  toPre() {
		 	ifthis.$refs.cusPage){
		 		this.$refs.cusPage.prev()
		 	}
		 },
		 currentChange(val) {
		  this.currenPage = val;
		  this.$emit('current-change',val);
	     },
	     sizeChange (val) {
		  this.pageSize= val;
		  this.$emit('size-change',val);
	     }
	   },
	 computed:{
	 //计算出当前的总页数
	  allPage() {
	    return Math.max(1,Math.ceil(Number(this.total)/Number(this.pageSize))
	  }
	 },
	 render (h) {
		const pageprops =
			props: {
				layout: 'total, slot,sizes, prev, pager,'
				pagesize: this-pagesize, 
				currentPage: this.currentPage, 
				total: 100,
			}
		}
		return (
			<el-pagination
				class="page-custome"
				{...pageprops} 
				ref-"cusPage" 
				onCurrent-change={(v)=>{this.currentChange(v)}} 
				onSize-change={(v)=>{this.sizeChange (v)}}
				onPrev-click={(v) =>{this.PrevChange (v)}}
				onNext-change={(v)=>{this.NextChange (v)}}
				<template slot="default">
				{this.setslot(h)}
				</template>
			</el-pagination>
		  )
	   }
}


组件内使用

<cus-page :total="100" @current-change="currentChange" ...></cus-page>

实现效果图

在这里插入图片描述
里面具体的逻辑可以自己实现下。

  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值