https://blog.csdn.net/yangwei282367751/article/details/82722840

分页组件
<template>
  <div>
    <div class="page-helper" v-if="showPageHelper">
      <div class="page-list">
        <span>共{{ totalPage }}页 / {{ totalCount }}条</span>
        <span class="page-item" @click="jumpPage(1)">首页</span>
        <span class="page-item" :class="{'disabled': currentPage === 1}"  @click="prevPage">上一页</span>
        <span class="page-ellipsis" v-if="showPrevMore" @click="showPrevPage">...</span>
        <span class="page-item" v-for="num in groupList" :class="{'page-current':currentPage===num}" :key="num"
              @click="jumpPage(num)">{{num}}</span>
        <span class="page-ellipsis" v-if="showNextMore" @click="showNextPage">...</span>
        <span class="page-item" :class="{'disabled': currentPage === totalPage}" @click="nextPage">下一页</span>
        <span class="page-item" @click="jumpPage(totalPage)">末页</span>
        <select class="page-select" @change="jumpPage(currentPage)" v-model="currentSize">
          <option v-for="size in pageSizeArray" :key="size" :value="size">{{ size }}条/页</option>
        </select>
        <span class="ml20">跳至</span>
        <span class="page-jump-to"><input type="type" v-model="jumpPageNumber"></span>
        <span>页</span>
        <span class="page-item jump-go-btn" @click="goPage(jumpPageNumber)">GO</span>
      </div>
    </div>
  </div>
</template>
 
<script>
export default {
  name: 'pageHelper',
  data () {
    return {
      currentPage: this.pageNumber,
      currentSize: this.pageSizeArray[0],
      jumpPageNumber: 1,
      showPrevMore: false,
      showNextMore: false
    }
  },
  props: {
    pageNumber: {   //当前页面
      type: Number,
      default: 1
    },
    pageSizeArray: {   //每页显示数量
      type: Array,
      default () {
        return [10,20,30,50]
      }
    },
    totalCount: {   //总条数
      type: Number,
      default: 1000
    },
    pageGroup: {   //连续页码个数
      type: Number,
      default: 5
    }
  },
  computed: {
    showPageHelper () {
      return this.totalCount > 0
    },
    totalPage () {   //总页数
      return Math.ceil(this.totalCount / this.currentSize);
    },
    groupList () {  //获取分页码
      const groupArray = []
      const totalPage = this.totalPage
      const pageGroup = this.pageGroup
      const _offset = (pageGroup - 1) / 2
      let current = this.currentPage
      const offset = {
        start: current - _offset,
        end: current + _offset
      }
      if (offset.start < 1) {
        offset.end = offset.end + (1 - offset.start)
        offset.start = 1
      }
      if (offset.end > totalPage) {
        offset.start = offset.start - (offset.end - totalPage)
        offset.end = totalPage
      }
      if (offset.start < 1) offset.start = 1
      this.showPrevMore = (offset.start > 1)
      this.showNextMore = (offset.end < totalPage)
      for (let i = offset.start; i <= offset.end; i++) {
        groupArray.push(i)
      }
      return groupArray
    }
  },
  methods: {
    prevPage () {
      if (this.currentPage > 1) {
        this.jumpPage(this.currentPage - 1)
      }
    },
    nextPage () {
      if (this.currentPage < this.totalPage) {
        this.jumpPage(this.currentPage + 1)
      }
    },
    showPrevPage() {
      this.currentPage = this.currentPage - this.pageGroup > 0 ? this.currentPage - this.pageGroup : 1
    },
    showNextPage() {
      this.currentPage = this.currentPage + this.pageGroup < this.totalPage ? this.currentPage + this.pageGroup : this.totalPage
    },
    goPage (jumpPageNumber) {
      if(Number(jumpPageNumber) <= 0){
        jumpPageNumber = 1
      }if(Number(jumpPageNumber) >= this.totalPage){
        jumpPageNumber = this.totalPage
      }
      this.jumpPage(Number(jumpPageNumber))
    },
    jumpPage (pageNumber) {
      if (this.currentPage !== pageNumber) {  //点击的页码不是当前页码
        this.currentPage = pageNumber
      //父组件通过change方法来接受当前的页码
      this.$emit('jumpPage', {currentPage: this.currentPage, currentSize: this.currentSize})
      }
    }
  },
  watch: {
    currentSize (newValue, oldValue) {
      if(newValue !== oldValue){
        if(this.currentPage >= this.totalPage){ //当前页面大于总页面数
          this.currentPage = this.totalPage
        }
        this.$emit('jumpPage', {currentPage: this.currentPage, currentSize: this.currentSize})
      }
    }
  }
}
</script>
 
<style scoped>
  .page-helper {
    font-weight: 500;
    height: 40px;
    text-align: center;
    color: #888;
    margin: 10px auto;
  }
  .page-list {
    font-size: 0;
    height: 50px;
    line-height: 50px;
  }
  .page-list span {
    font-size: 14px;
    margin-right: 5px;
    user-select: none;
  }
  .page-list .page-item {
    border: 1px solid #aaa;
    padding: 5px 8px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 5px;
  }
  .page-ellipsis {
    padding: 0 8px;
  }
  .page-jump-to input {
    width: 45px;
    height: 26px;
    font-size: 13px;
    border: 1px solid #aaa;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    text-align: center;
  }
  .page-list .jump-go-btn {
    font-size: 12px;
  }
  .page-select{
    border: 1px solid #aaa;
    padding: 5px 8px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 5px;
    margin-left: 5px;
  }
  .page-list .page-item .disabled{
    pointer-events: none;
    background: #ddd;
  }
  .page-list .page-current {
    cursor: default;
    color: #fff;
    background: #337ab7;
    border-color: #337ab7;
  }
</style>

父页面

<page-helper @jumpPage="jumpPage" :page-number="pageNumber" page-size-array="PageSizeArray"></page-helper>

效果图

vue2自定义分页组件,可设置每页显示数量,指定跳转具体页面相关推荐

  1. Angular 自定义分页组件,自定义每页显示个数

    后端返回列表是全部数据,分页前端做的,自定义分页组件实现前端分页,下图为分页效果: 1.创建page.component.html <nav class="navigation&quo ...

  2. mvc jquery ajax分页实例,jQuery Ajax自定义分页组件(jquery.loehpagerv1.0)实例详解,mvcpagerajax分页...

    jQuery Ajax自定义分页组件(jquery.loehpagerv1.0)实例详解,mvcpagerajax分页 简单的两个步骤即可实现分页功能 //回调里面进行业务处理 function lo ...

  3. GridView自定义分页样式(上一页,下一页,到第几页)(新手教程)

    今天要为网站做一个文章列表,发现GridView的分页样式很难看,于是结合网上的例子,自己做了一个.不是很美观,不过还是很实用的,先看下效果吧,如图(1).演示地址http://www.veryam. ...

  4. Python自定义分页组件

    为了防止XSS即跨站脚本攻击,需要加上 safe # 路由 from django.conf.urls import url from django.contrib import admin from ...

  5. 关于element-ui的分页器设置每一页显示数量(page-size)后页码并没有变化的问题与解决

    问题:element-ui的分页器在设置后,总页面数异常,不匹配总条数与单页显示数,设置page-size后页面也无变化 <ElPagination style="textAlign: ...

  6. android 中间凸出按钮,自定义tabar组件,中间按钮凸出显示

    更新记录 1.0.1(2020-11-17) 1.把图标更改成本地路径. 2.上传插件包时,如果包含static文件,一直提示不存在的错误,导致无法上传. 3.插件包仅包含components文件,所 ...

  7. C++ cad设置视角居中显示在指定坐标以及视口的宽度和高度设置

    //设置当前视图         AcDbViewTableRecord view;         struct resbuf       rb;         struct resbuf     ...

  8. Django 分页组件替换自定义分页

    Django的分页器(paginator) 总之不太好用我们还是用自己的好一些 自定义分页器 分页实现源码 """ 自定义分页组件 """c ...

  9. yishaadmin,yishaadmin修改数据后回到起始页的解决办法,保持在修改前的页码,分页组件在修改数据后不返回到第一页

    用过一沙框架开发的知道,一沙封装了很多js通用的方法,组件,其中ysTable()便是其中之一. 分页组件是包含在ysTable()中的,其中的分页组件,只有选择器类名,没有唯一的ID定位, 通过看页 ...

最新文章

  1. workbench设置单元坐标系_Workbench菜单选项中英文对照
  2. 【任务脚本】京jd东jd炸年兽活动任务全自动程序
  3. 找出一堆数中最小的前K个数
  4. oracle 如何表分析,ORACLE的表分析策略
  5. docker中使用golang:alpine镜像制作开启goweb的dockerfile
  6. 全国计算机等级考试题库二级C操作题100套(第16套)
  7. 使用DataGrip连接Hive
  8. html中的数字选框,带有复选框和数字类型的HTML表单提交与PHP?
  9. SQL Server 查询性能优化——覆盖索引(一)
  10. 数据结构中的7种排序算法
  11. CvtColor(转)
  12. 一个完整的物联网项目管理流程
  13. python提取cad坐标_从CAD图里提取坐标的方法
  14. 手机怎么下载python呢_安卓手机端怎么安装Python?
  15. ROS学习笔记(二)launch文件初步使用
  16. ce游戏逆向修改之植物大战僵尸
  17. 3D游戏建模师薪水大概是多少?从人生经历来看
  18. JavaScript实现树结构(一)
  19. 一文了解RT8059GJ5
  20. 牛顿迭代法 matlab程序

热门文章

  1. Cocos2d-x-3.0rc0创建新项目
  2. Unity3D游戏开发之GUI
  3. 基于Linux操作系统的底层驱动技术
  4. Office 2010、Project 2010、Visio 2010
  5. 1054: 猴子吃桃
  6. 华为交换机的端口hybrid端口属性配置
  7. Sql 列转行 三种方法对比
  8. iOS 操作系统被曝无线网络命名bug 导致 iPhone无法连接无线网络
  9. SolarWinds 事件新动态:研究员发现新的C2基础设施
  10. docker machine介绍和使用