el-pagination分页组件封装

该博客介绍了如何在Vue.js应用中创建一个自定义的分页组件`pagination.js`,该组件包括了页面大小切换、当前页数变更等功能,并通过`@change`事件触发父组件的数据获取方法。在`index.js`中,这个分页组件被引用并用于表格数据的加载,提供了搜索和刷新列表的操作。
摘要由CSDN通过智能技术生成

pagination.js

<template>
  <div class="pagination-container">
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="comCurrentPage"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      :layout="layout"
      :total="total"
      style="float: right">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'pagination',
  data () {
    return {
      pageSize: this.pageSizes[0],
      comCurrentPage: this.currentPage
    }
  },
  props: {
    layout: {
      type: String,
      default () {
        return 'total, sizes, prev, pager, next, jumper'
      }
    },
    pageSizes: { // 每页显示数量
      type: Array,
      default () {
        return [10, 20, 50, 100]
      }
    }, 
    total: { // 数据总量
      type: Number,
      required: true
    }, 
    currentPage: { // 当前页
      type: Number,
      default: 1
    }, 
    changeCallback: {
      type: Function,
      required: true
    }
  },
  methods: {
    /*
    每页显示数量改变
    * */
    handleSizeChange (val) {
      this.pageSize = val
      this.changeCallback(this.comCurrentPage, this.pageSize)
    },
    /*
    页面跳转
    * */
    handleCurrentChange (val) {
      this.comCurrentPage = val
      this.changeCallback(this.comCurrentPage, this.pageSize)
    },
    /*
    刷新
    * */
    refresh () {
      this.changeCallback(this.comCurrentPage, this.pageSize)
    },
    /*
    搜素/初始化列表
    * */
    search () {
      this.pageSize = this.pageSizes[0]
      this.comCurrentPage = 1
      this.changeCallback(this.comCurrentPage, this.pageSize)
    }
  }
}
</script>

index.js

<pagination ref="page" :total="total" :change-callback="getTableList"></pagination>
<script>
import pagination from '@/components/pagination'
export default {
    components: { pagination },
    data() {
        return {
            total: 0,
        }
    },
mounted() {
    this.getTableList()
  },
methods: {
search() {
      this.$refs.page.search()
    },

}
}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值