el-pagination分页二次封装

10 篇文章 0 订阅
9 篇文章 0 订阅

el-pagination分页二次封装


main.js引入全局组件

1. 组件

page.vue

<template>
  <!--分页-->
  <!-- <div class="page_block" v-if="this.pages > 0"> -->
  <div class="page_block">
    <el-pagination background layout="total, sizes, slot,->" :total="total" :page-sizes="pageArr" :page-size="pageSize" :current-page="currPage" @current-change="handleCurrentChange" @size-change="handleSizeChange">
      <span>共 {{this.pages}} 页</span>
    </el-pagination>
    <el-pagination background layout="slot, prev, next" :total="total" :page-sizes="pageArr" :page-size="pageSize" :current-page="currPage" prev-text="上一页" next-text="下一页" @current-change="handleCurrentChange" @size-change="handleSizeChange">
      <el-button type="text" :disabled="currPage === 1" @click="handleCurrentChange(1)">首页</el-button>
    </el-pagination>
    <el-pagination background layout="slot" :total="total" :page-sizes="pageArr" :page-size="pageSize" :current-page="currPage" @current-change="handleCurrentChange" @size-change="handleSizeChange">
      <el-button type="text" :disabled="currPage === pages" @click="handleCurrentChange(pages)">末页</el-button>
    </el-pagination>
    <el-pagination background layout="jumper,slot" :total="total" :page-sizes="pageArr" :page-size="pageSize" :current-page="currPage" @current-change="handleCurrentChange" @size-change="handleSizeChange">
      <!-- <el-button type="primary" @click="handleCurrentChange(currPage)">确定</el-button> -->
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'index',
  data() {
    return {
      pageArr: [1, 5, 10, 20, 30, 40, 50],
      total: this.$store.state.page.total,
      pageSize: this.$store.state.page.pageSize,
      currPage: this.$store.state.page.currPage,
      pages: this.$store.state.page.pages,
    }
  },
  components: {},
  mounted() {
  },
  methods: {
    //每页展示条数
    handleSizeChange(val) {
      //事件传递
      this.$emit('handleSizeChangeSub', val)
    },
    //当前页
    handleCurrentChange(val) {
      //事件传递
      this.$emit('handleCurrentChangeSub', val)
    }
  },
  watch: {
    '$store.state.page.total'() {
      this.total = this.$store.state.page.total
    },
    '$store.state.page.pageSize'() {
      this.pageSize = this.$store.state.page.pageSize
    },
    '$store.state.page.currPage'() {
      this.currPage = this.$store.state.page.currPage
    },
    '$store.state.page.pages'() {
      this.pages = this.$store.state.page.pages
    },
  },
  created() {
  },
  // 过滤器设计目的就是用于简单的文本转换
  filters: {},
  // 若要实现更复杂的数据变换,你应该使用计算属性
  computed: {},
}
</script>

<style scoped>
.el-pagination {
  padding: 0 !important;
  display: inline-block;
}

.el-pagination .el-select .el-input {
  margin: 0;
}

.page_block /deep/ .el-pagination .btn-prev,
.page_block /deep/ .el-pagination .btn-next {
  padding: 0 6px !important;
  background: none !important;
  margin: 0;
}

/* .el-pagination button {
  margin: 0 !important;
  background: none;
} */

/* .el-pagination .el-button--primary {
  background-color: #2D7DEC !important;
  color: #fff !important;
  margin: 0 0 0 5px !important;
} */
</style>


2. 调用

<pages @handleCurrentChangeSub="handleCurrentChangeFun" @handleSizeChangeSub="handleSizeChangeFun"></pages>
// ------------------ 分页 ------------------
handleCurrentChangeFun(v) {
  // 点击的页码、当前页,更新vuex存储的页码
  this.$store.commit('page/change_currPage', v)
  // 调自定义方法更新列表
  this.myFun()
},
handleSizeChangeFun(v) {
  // 选择每页条数,更新vuex存储的每页条数
  this.$store.commit('page/change_pageSize', v)
  // 调自定义方法更新列表
  this.myFun()
},
  • 10
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值