vue element-ui 分页组件封装

时间:2021-09-18 21:06:04
<template>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" style="float:right;">
    </el-pagination>
</template>
<script type="text/ecmascript-6">
export default {
    components: {

    },
    data() {
        return {

        }
    },
    props: {
        pageSize: {
            type: Number,
            default: 10
        },
        total: {
            type: Number,
            default: 1
        }
    },
    watch: {

    },
    methods: {
        //每页展示条数
        handleSizeChange(val) {
            //事件传递
            this.$emit('handleSizeChangeSub', val);
        },
        //当前页
        handleCurrentChange(val) {
            //事件传递
            this.$emit('handleCurrentChangeSub', val);
        }
    },
    // 过滤器设计目的就是用于简单的文本转换
    filters: {},
    // 若要实现更复杂的数据变换,你应该使用计算属性
    computed: {

    },
    created() {

    },
    mounted() {},
    destroyed() {}
}
</script>
<style lang="scss" type="text/css" scoped>
</style>

调用

// 分页
import pages from 'components/common/pages/pages'

components: {
  pages
},

<pages :total="total" :page-size="pageSize" @handleSizeChangeSub="handleSizeChangeFun" @handleCurrentChangeSub="handleCurrentChangeFun"></pages>

handleSizeChangeFun(v) {
  this.pageSize = v;
  this._enterpriseList(); //更新列表
},

handleCurrentChangeFun(v) { //页面点击
  this.pageNum = v; //当前页
  this._enterpriseList(); //更新列表
}