vue如何使用element-ui 实现自定义分页
更新时间:2024年07月19日 10:03:16 作者:小瓶子
这篇文章主要介绍了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() {
if(this.$refs.cusPage){
this.$refs.cusPage.next()
}
},
toPre() {
if(this.$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>
实现效果图

里面具体的逻辑可以自己实现下。
到此这篇关于vue使用element-ui 实现自定义分页的文章就介绍到这了,更多相关vue element-ui 分页内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
vue上传文件formData入参为空,接口请求500的解决
这篇文章主要介绍了vue上传文件formData入参为空,接口请求500的解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-06-06
ant design中upload组件上传大文件,显示进度条进度的实例
这篇文章主要介绍了ant design中upload组件上传大文件,显示进度条进度的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-10-10
Vue3+ts+setup getCurrentInstance使用时遇到的问题以及解决办法
getCurrentInstance方法用于获取当前组件实例,仅在setup和生命周期中起作用,下面这篇文章主要给大家介绍了关于Vue3+ts+setup getCurrentInstance使用时遇到的问题以及解决办法,需要的朋友可以参考下2022-08-08


最新评论