Elementui自定义Pagination 上一页下一页使用按钮

一 效果图

二 上代码

<el-button size="small" @click="pervious">上一页</el-button>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="current"
      :page-size="pageSize"
      layout="pager"
      :total="total"
      ref="pageGroup">
    </el-pagination>
    <el-button size="small" @click="next">下一页</el-button>

current-page如果你是封装在组件里面props里面传过来的值是不能直接赋予的因为切换上一页下一页当前页会改变, props里面值不允许修改不然控制台会一直报错

elementui提供的方法

pervious() {
      this.$refs.pageGroup.prev()
    },
    next() {
      this.$refs.pageGroup.next()
    },

调用一下就ok了, 上一页,下一页可以是按钮或者各种自定义的logo都可以, 注意layout里面,文档提供的是箭头的形式

加油加油   顺带写一下继续搬砖

更新组件,自己稍微封装了一下,还可以根据自身修改

<TablePaging :currentPage="currentPage" :total="total" :pageSize="pageSize" @pageChange="pageChange"/>
<template>
  <div class="pageGroup">
    <el-button size="small" @click="pervious">上一页</el-button>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="current"
      :page-size="pageSize"
      layout="pager"
      :total="total"
      ref="pageGroup">
    </el-pagination>
    <el-button size="small" @click="next">下一页</el-button>
  </div>
</template>

<script>
export default {
  name: 'TablePaging',
  props: {
    currentPage: Number,
    pageSize: Number,
    total: Number,
  },
  data() {
    return {
      current: 1,
    }
  },
  watch: {
    currentPage: {
      handler() {
        this.current = this.currentPage
      },
      deep: true,
    },
  },
  created() {
    this.current = this.currentPage
  },
  methods: {
    handleSizeChange(val) {
      console.log(val)
    },
    handleCurrentChange(val) {
      //console.log(val)
      this.$emit('pageChange', val)
    },
    pervious() {
      this.$refs.pageGroup.prev()
    },
    next() {
      this.$refs.pageGroup.next()
    },
  },
}
</script>

<style>
.el-pager li {
  font-size: 12px;
  height: 24px;
  line-height: 18px;
  padding: 0 5px;
  box-sizing: border-box;
}
</style>

  • 7
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值