element分页的简单封装组件
<template>
<div :class="{ hidden: hidden }" class="pagination-container">
<el-pagination
v-show="total > pageSizes[0]"
:background="background"
:current-page.sync="currentPage"
:page-size.sync="pageSize"
:layout="layout"
:page-sizes="pageSizes"
:total="total"
v-bind="$attrs"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</template>
<script>
import { scrollTo } from '@/utils/scroll-to'
export default {
name: 'Pagination',
props: {
total: {
required: true,
type: Number
},
page: {
type: Number,
default: 1
},
limit: {
type: Number,
default: 20
},
pageSizes: {
type: Array,
default () {
return [12, 24, 36, 48, 96]
}
},
layout: {
type: String,
default: 'sizes,total,prev, pager, next'
},
background: {
type: Boolean,
default: true
},
autoScroll: {
type: Boolean,
default: true
},
hidden: {
type: Boolean,
default: false
}
},
computed: {
currentPage: {
get () {
return this.page
},
set (val) {
this.$emit('update:page', val)
}
},
pageSize: {
get () {
return this.limit
},
set (val) {
this.$emit('update:limit', val)
}
}
},
methods: {
handleSizeChange (val) {
this.$emit('update:page', 1)
this.$emit('pagination', { page: this.currentPage, limit: val })
if (this.autoScroll) {
scrollTo(0, 800)
}
},
handleCurrentChange (val) {
this.$emit('pagination', { page: val, limit: this.pageSize })
if (this.autoScroll) {
scrollTo(0, 800)
}
}
}
}
</script>
<style scoped>
.pagination-container {
margin-top: 16px;
background: #fff;
padding: 20px 0;
}
.pagination-container.hidden {
display: none;
}
</style>
页面使用
<pagination
:total="totalCount"
:page.sync="currentPage"
:limit.sync="pageSize"
@pagination="get_DataElement"
/>
<!-- get_DataElement函数是获取当前table表格数据的 -->