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>

实现效果图

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

最近更新

  1. TCP协议是安全的吗?

    2024-03-19 15:44:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-19 15:44:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-19 15:44:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-19 15:44:02       18 阅读

热门阅读

  1. 一文解读ISO26262安全标准:初步危害分析PHA

    2024-03-19 15:44:02       16 阅读
  2. 分享SQL的7种进阶用法

    2024-03-19 15:44:02       18 阅读
  3. codetop刷题笔记1——两数之和/iota/lambda表达式

    2024-03-19 15:44:02       19 阅读
  4. 【sql】初识 where EXISTS

    2024-03-19 15:44:02       20 阅读
  5. Bash Shell中单引号和双引号的区别详解

    2024-03-19 15:44:02       24 阅读
  6. Git速成

    Git速成

    2024-03-19 15:44:02      16 阅读
  7. openh264初探

    2024-03-19 15:44:02       14 阅读
  8. 工程化专栏目录

    2024-03-19 15:44:02       19 阅读
  9. vue项目- el-table表格合并行

    2024-03-19 15:44:02       18 阅读