ant-design-vue Table分页组件的自定义

news/2024/7/10 1:52:48 标签: vue

分页组件用的最多的就是和表格一起,构成表格数据的翻页显示,当然也不仅限于表格,还有很多

这里以表格为例,通常我们写一个分页展示的表格,都会写一个,然后在下面再写一个的分页组件,分页组件里面有很多参数和触发函数,比如::page-sizes :total :current-page :page-size 及 layout等,触发函数一般有 @current-change @size-change 等,而以上的参数和触发函数对于一个项目中用到的所有分页组件几乎都是一样的,如果我们每写一个翻页表格,再写一个分页组件,这样就会显得很啰嗦,重复代码多。

这里,我们把组件进一步封装成,引入需要用的文件中,再写翻页表格时,只需引入或有按需求传入自己的参数,不需要写重复的参数和触发函数。
效果图
在这里插入图片描述

组件如下,不懂的地方请留言

<template>
  <a-pagination class="pagination" v-if="total>10" v-model="current" :total="total" :size="size" :showTotal="(total, range)=> `共 ${total} 条`" :hideOnSinglePage="hideOnSinglePage" :showQuickJumper="showQuickJumper" :showSizeChanger="showSizeChanger" :pageSize.sync="currentPageSize" :pageSizeOptions="pageSizeOptions" @change="change" @showSizeChange="showSizeChange">
  </a-pagination>
</template>

<script>
export default {
  name: 'pagination',
  props: {
    currents: { // 当前页
      type: Number,
      default: 1
    },
    hideOnSinglePage: {   //只有一页时是否隐藏分页器
      type: Boolean,
      default: false,
    },
    pageSize: {  //每页条数
      type: Number,
      default: 10
    },
    pageSizeOptions: {  //指定每页可以显示多少条
      type: Array,
      default() {
        return ['10', '20', '30', '50',]
      },
    },
    showQuickJumper: {  //是否可以快速跳转至某页
      type: Boolean,
      default: true,
    },
    showSizeChanger: {  //是否可以改变 pageSize
      type: Boolean,
      default: true,
    },
    simple: {    //当添加该属性时,显示为简单分页
      type: Boolean,
      default: false,
    },
    size: {  //当为「small」时,是小尺寸分页
      type: String,
      default: '',
    },
    total: {   //数据总数
      type: Number,
      default: 1,
    },
  },
  data() {
    return {
      // 当前页
      current: this.currents,
      //每页条数
      currentPageSize: this.pageSize,
    }
  },
  watch: {
    currents(val) {
      this.current = val
    },
    pageSize(val) {
      this.currentPageSize = val
    },
  },
  methods: {
    //页码改变的回调,参数是改变后的页码及每页条数
    change(page, pageSize) {
      this.$emit('page', page)
      this.$emit('pageSize', pageSize)
      this.$emit('pagination', page, pageSize)
    },
    //pageSize 变化的回调
    showSizeChange(current, size) {
      //   console.log(current)
      //   console.log(size)
      this.$emit('page', current)
      this.$emit('pageSize', size)
      this.$emit('pagination', current, size)
    },
  },
}
</script>
<style lang="less" scoped>
.pagination {
  text-align: center;
  padding-bottom: 30px;
}
</style>

引用的页面用法,如下
在这里插入图片描述

 <pagination v-show="total>0" :total="total" @page="pages" @pageSize="pageSizes" :currents="form.current" :pageSize="form.size" @pagination="getList" />
 

一开始需要查几条数据
在这里插入图片描述
改变页数的时候
在这里插入图片描述


http://www.niftyadmin.cn/n/874755.html

相关文章

Vue中的scoped的实现原理以及scoped穿透的用法(附代码)

本篇文章给大家带来的内容是关于Vue中的scoped的实现原理以及scoped穿透的用法&#xff08;附代码&#xff09;&#xff0c;有一定的参考价值&#xff0c;有需要的朋友可以参考一下&#xff0c;希望对你有所帮助。 1.什么是scoped 在Vue文件中的style标签上有一个特殊的属性&…

vue中使用vue-quill-editor富文本编辑器,自定义toolbar修改工具栏options

1.概述 在项目中&#xff0c;会需要使用富文本编辑器去编辑文字、上传图片、视频等信息去描述某一个物品的详细信息与介绍。可使用vue的图文编辑vue2-editor去处理这些事情。 首先进行vue2-editor安装 npm install vue2-editor --save 安装至项目中富文本的使用   在使用vue…

拼接td并改变其中一个背景色_干货|黄金TD、白银TD与账户金、账户银的对比

最近有朋友叫我写一篇黄金TD、白银TD与账户金、账户银的对比&#xff0c;让他更好的选择哪个投资品种会更好些&#xff0c;现在为他安排上&#xff01;工行E投行客户端账户金名为账户贵金属&#xff0c;又名为人民币账户黄金&#xff0c;只要在各大银行APP上开通贵金属业务&…

关于wangEditor的覆盖问题 以及修改默认高度

用富文本编辑器的的时候&#xff0c;发现弹框被富文本编辑器覆盖了 经过查看控制台发现 wangEditor设置的z-index很大&#xff0c;为1000&#xff0c;所以会覆盖掉和他重合的区域&#xff0c;加入下面代码就行 <style lang"less"> //修改默认高度 .w-e-tex…

引入antd组件样式_antd组件样式局部加载,用react-app-rewired插件应该怎么配置?...

package.json配置&#xff1a;{"name": "hawerblog","version": "0.1.0","private": true,"dependencies": {"antd": "^3.15.0","babel-plugin-import": "^1.11.0",&quo…

Vue+elementUi的日期选择器 ,选择范围的限制不能大于或者小于当前时间

直接上干货&#xff01; <el-form-item label"失效时间:" prop"failure"><el-date-picker v-model"ruleForm.failure" type"date" value-format"yyyy-MM-dd" placeholder"选择日期" :picker-options&quo…

shell export path_Shell脚本提高你的效率之变量篇

头条号&#xff1a;浩渺烟波Shell是一个命令行解释器&#xff0c;它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序&#xff0c;用户可以用shell来启动&#xff0c;挂起停止甚至编写一些程序。Shell 处在内核与外层应用程序之间&#xff0c;起着协调用户与系…

js 获取某一年份到当前年份的所有年份

最近碰到个关于年份的下拉框 后端只返回从哪一年开始&#xff0c;然后我们要回去当前年&#xff0c;以及这之间的几年 下面直接上代码&#xff0c;不懂请留言。 //获取到从那一年开始this.smallYears res.msg//获取当前时间var date new Date;this.nowYears date.getFullYe…