<template>
<div class="pagination_center" v-show="total !== 0">
<el-pagination
: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>
export default {
name: "Pagination",
props: {
total: {
type: Number,
required: true
},
page: {
type: Number,
default: 3
},
limit: {
type: Number,
default: 10
},
pageSizes: {
type: Array,
default: () => {
return [10, 20, 30, 40, 50];
}
},
layout: {
type: String,
default: "total,prev,pager,next"
},
background: {
type: Boolean,
default: false
},
autoScroll: {
type: Boolean,
default: true
},
hidden: {
type: Boolean,
default: false
}
},
computed: {
currentPage: {
get() {
return;
},
set(val) {
this.$emit("update:page", val);
}
},
pageSize: {
get() {
return;
},
set(val) {
this.$emit("update:limit", val);
}
}
},
methods: {
handleSizeChange(val) {
this.$emit("handleSizeChange", { page: this.currentPage, limit: val });
},
handleCurrentChange(val) {
this.$emit("handleCurrentChange", { page: val, limit: this.pageSize });
}
}
};
</script>
<style>
.pagination_center {
width: 100%;
text-align: center;
margin-top: 20px;
}
.el-pagination__total {
font-size: 20px;
color: #fff;
}
.el-pagination__jump {
font-size: 20px;
color: #fff;
}
.el-pagination.is-background .el-pager li {
border-radius: 30px !important;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
background: #feb733 !important;
}
</style>
在父组件中的使用:
引入
import Pagination from "@/components/Pagination";
注册
components: {
Pagination,
},
使用
<Pagination
background
:total="xx_count"
:page.sync="userxx_page"
:limit.sync="userxx_rows"
@handleCurrentChange="handleCurrentChange"
@handleSizeChange="handleSizeChange"
/>
data() {
return {
count: 0,
activeName: "0", //当前查看的消息参数
userxx_page: 1, // 消息页数
userxx_rows: 10, // 消息条数
userxx_allpages: "", // 总共几页
activecurrent: 0,
};
},
methods: {
// 列表上下页---------------------------------------------
handleCurrentChange(res) {
this.GetMyMessageList(this.activecurrent);
},
// 列表一页多少条---------------------------------------------
handleSizeChange(res) {
console.log(res);
},
}