1、pagination组件
<template>
<div class="block">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="pageN.currentPage"
:page-sizes="pageN.pageSizes"
:page-size="pageN.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="pageLength"
>
</el-pagination>
</div>
</template>
props:{
pageLength:{
default:0
},
pageN:{
default:{}
}
},
methods: {
handleSizeChange(val) {
this.$emit("sizeChange",val);
},
handleCurrentChange(val) {
this.$emit("jumpPage",val);
}
},
2、父组件
<list :post1="posts"></list>
<pagination
class="pagination"
:pageN="pageN"
:pageLength="post.length"
@jumpPage="jump"
@sizeChange="sizeChange"
></pagination>
data() {
return {
pageN: {
currentPage: 1,
pageSizes: [2, 3, 5, 10],
pageSize: 10,
},
post:[]
}
},
computed: {
posts() {
return this.post.slice(
this.pageN.pageSize * (this.pageN.currentPage - 1),
this.pageN.pageSize * this.pageN.currentPage
);
},
},
methods: {
sizeChange(val) {
this.pageN.pageSize = val;
this.pageN.currentPage = 1;
},
jump(val) {
this.pageN.currentPage = val;
console.log(val);
},
},
|