美文网首页前端
基于element分页器简单封装

基于element分页器简单封装

作者: 一个健康马 | 来源:发表于2020-06-11 17:32 被阅读0次
//导入
<pagination 
                  :total='page.total' 
                  :page='page.current' 
                  :limit='page.size'
                  @update:limit='updatelimit' 
                  @update:page='updatepage'
                  @pagination='pagination'></pagination>

import Pagination from "../comments/Pagination/index"
//data
//分页
      page:{
        total:10,
        current:1,
        size:10,
      },
//方法
//获取接口列表
    getinterface(val){  
      request('/md/conf/data/dataInfo/selectPage', val, (flag, data, res) => {  
        this.page={
          total:data.total,
          current:data.current,
          size:data.size
        }
        }, () => {
        });
      },
//分页条数
     pagination(val){
      this.page.current=val.page
      this.page.size=val.limit
      this.getinterface({size:this.page.size,current:this.page.current})
    },
//条数回调
    updatelimit(val){
      this.page.size=val
      // this.getinterface({size:this.page.size,current:this.page.current})
    },
//页数回调
    updatepage(val){
      this.page.current=val
      // this.getinterface({size:this.page.size,current:this.page.current})
    },
//分页器
<template>
  <div :class="{'hidden':hidden}" class="pagination-container">
    <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: {
      required: true,
      type: Number
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number, 
      default: 20
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50]
      }
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    } 
  },
  methods: {
    // 每条页数
    handleSizeChange(val) {
      this.$emit('pagination', { page: this.currentPage, limit: val })

    },
    // 当前页
    handleCurrentChange(val) {
      this.$emit('pagination', { page: val, limit: this.pageSize })
    }
  }
}
</script>

<style scoped>
.pagination-container {
  /* background: #fff; */
  padding: 0 16px 32px;
}
.pagination-container.hidden {
  display: none;
}
.el-pagination {
    text-align: center;   
}
</style>

相关文章

网友评论

    本文标题:基于element分页器简单封装

    本文链接:https://www.haomeiwen.com/subject/yptitktx.html