vue封装element-ui分页

# Pagination.vue

src/components/Pagination.vue

<template>
  <div class="mt-3">
    <el-pagination
      @size-change="handleSize"
      @current-change="handleCurrent"
      :current-page="page2"
      :page-sizes="sizes"
      :page-size="size2"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "index",
  props: {
    // 页数大小数组
    sizes: {
      type: Array,
      default: function() {
        return [10, 20, 50, 100, 200, 500];
      }
    },
    // 分页显示多少条信息
    size: {
      type: Number,
      default: function() {
        return 10;
      }
    },
    // 当前页
    page: {
      type: Number,
      default: function() {
        return 1;
      }
    },
    // 总共多少条
    total: {
      type: Number,
      default: function() {
        return 0;
      }
    }
  },
  data() {
    return {
      size2: this.size,
      page2: this.page
    };
  },
  mounted() {},
  methods: {
    /**
     * @description: 改变了分页大小
     * @author: chenbz
     * @date: 2021/4/25
     */
    handleSize(size) {
      this.page2 = 1;
      this.size2 = size;
      let data = {
        page: this.page2,
        size: size
      };
      this.$emit("handlePagination", data);
    },
    /***
     * @description: 改变了分页页数
     * @author: chenbz
     * @date: 2021/4/25
     */
    handleCurrent(current) {
      this.page2 = current;
      let data = {
        page: current,
        size: this.size2
      };
      this.$emit("handlePagination", data);
    }
  }
};
</script>

<style scoped></style>


# 页面引用

Test.vue

<template>
  <div>
    test
    <MyPagination
      :total="pagination.total"
      @handlePagination="handlePagination"
    >
    </MyPagination>
  </div>
</template>

<script>
// 引入封装分页组件
import MyPagination from "@/components/Pagination.vue";
export default {
  name: "test",
  components: {
    MyPagination
  },
  data() {
    return {
      pagination: {
        total: 500
      }
    };
  },
  mounted() {},
  methods: {
    // 改变了分页
    handlePagination(val) {
      console.log(val);
    }
  }
};
</script>

<style></style>


# 参数说明
属性描述类型默认值
sizes页数大小数组Array[10, 20, 50, 100, 200, 500]
size分页显示多少条信息Number10
page当前页Number1
total总共多少条Number0


# 方法
方法名描述回调函数
@handlePagination改变了分页(Val)


# 效果图

Snipaste_2021-05-02_17-43-50

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值