element的分页组件:
<template>
<div class="paginationWrap">
<el-pagination
:current-page.sync="currentPage"
:page-size.sync="pageSize"
:layout="paginationLayout"
:page-sizes="pageSizes"
:total="total"
v-bind="$attrs"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</template>
<script>
export default {
name: 'Pagination',
props: {
pageSizes: {
type: Array,
default() {
return [10, 20, 30, 50, 500]
}
},
paginationLayout: { type: String, default: 'slot, total, sizes, prev, pager, next, jumper' },
total: { type: Number, default: 0 },
page: { type: Number, default: 1 },
background: { type: Boolean, default: true },
limit: { type: Number, default: 20 },
pageHidden: { type: Boolean, default: false }
},
data() {
return {}
},
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('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>
.paginationWrap {
margin-top: 30px;
}
.pagination-container {
padding: 16px 16px;
}
.pagination-container.hidden {
display: none;
}
.el-pagination {
width: 100%;
text-align: right;
}
.pagination /deep/ .el-pagination__jump {
float: right;
}
</style>
调用的页面:
<template>
<div>
<Pagination :total="totalCount" :page.sync="page" :limit.sync="listQuery.page.pageSize" @pagination="getDetail" />
</div>
</template>
<script>
import API from '@/api/base'
import Pagination from '../components/Pagination'
export default {
components: { Pagination },
data() {
return {
apiName: 'apiurl',
content : [],
listQuery: {
page: {
pageSize: 10,
pageIndex: 1
},
query: {}
},
page: 1,
totalCount: 0
}
},
mounted() {
this.getDetail()
},
methods: {
async getDetail(val) {
if (val) {
this.page = val.page
if (val.limit) {
this.listQuery.page.pageIndex = this.page
} else {
this.listQuery.page.pageIndex = this.page
}
}
await API.dataPost(this.apiName, this.listQuery, 'pageChange').then((res) => {
if (res.code === '0000') {
this.content = res.data.content
this.totalCount = parseInt(res.data.totalCount)
} else {
this.$notify({
title: '提示',
message: res.message,
duration: 2000,
type: 'warning'
})
}
})
}
}
</script>
<style scoped>
</style>