Vue 分页器组件[通俗易懂]

Vue 分页器组件[通俗易懂]<template><divclass=”pagination”><button>上一页</button><button@click=”changecurentpage(1)”v-if=”startEnd.start>1″>1</button><buttonv-if=”startEnd.start>2″>···</button><.

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

<template>
  <div class="pagination">
    <button>上一页</button>
    <button @click="changecurentpage(1)" v-if="startEnd.start > 1">1</button>
    <button v-if="startEnd.start > 2">···</button>

    <button @click="changecurentpage(startEnd.start+index)" v-for="(item,index) in continuPage" :key="index">{
  
  {startEnd.start+index}}</button>


    <button v-if="startEnd.end < pagesTotal -1">···</button>
    <button @click="changecurentpage(pagesTotal)" v-if="startEnd.end < pagesTotal">{
  
  {pagesTotal}}</button>
    <button>下一页</button>

    <button style="margin-left: 30px">{
  
  {currentPageNo}}/{
  
  {pagesTotal}}页</button>
  </div>
</template>

<script>
export default {
  props: ['currentPageno','pageSize','total','continuPage'],
  data() {
    return {
      currentPageNo : this.currentPageno
    }
  },
  methods: {
    changecurentpage(currentPageNo) {
      // if(this.startEnd.end)
      this.currentPageNo = currentPageNo
    }
  },
  computed: {
    pagesTotal() {
      return Math.ceil(this.total/this.pageSize)
    },
    startEnd() {
      let {currentPageNo,continuPage} = this
      let start = currentPageNo-parseInt(continuPage/2)
      if (start < 1) start = 1
      let end = currentPageNo+parseInt(continuPage/2)
      if (end > this.pagesTotal) {
        end = this.pagesTotal
        start = end - continuPage +1
      }
      return {start, end}
    }
  }
};
</script>

<style lang="less" scoped>
.pagination {
  text-align:center;
  button {
    margin: 0 5px;
    background-color: #f4f4f5;
    color: #606266;
    outline: none;
    border-radius: 2px;
    padding: 0 4px;
    vertical-align: top;
    display: inline-block;
    font-size: 13px;
    min-width: 35.5px;
    height: 28px;
    line-height: 28px;
    cursor: pointer;
    box-sizing: border-box;
    text-align: center;
    border: 0;

    &[disabled] {
      color: #c0c4cc;
      cursor: not-allowed;
    }

    &.active {
      cursor: not-allowed;
      background-color: #409eff;
      color: #fff;
    }
  }
}
</style>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/187346.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ssh用私钥生成公钥[通俗易懂]

    ssh用私钥生成公钥

    2022年2月19日
    61
  • Linux安装vim命令

    Linux安装vim命令最近在Linux上使用vim编辑器编写shell脚本的时候,遇到了这样一个问题,如下:-bash:vim:commandnotfound这是因为vim命令没有安装,于是我从网上搜索了很多关于安装vim命令的教程,不过大都比较繁琐,如今介绍一种简单的方法,大家可以试一下。首先,执行如下命令进行查询:rpm-qa|grepv…

    2022年10月23日
    0
  • CloudSim 学习实例1

    CloudSim 学习实例1Cloudsimexample1cloudsim教程例1解读创建一个含一台主机的数据中心,并在其上运行一个云任务代码packageorg.cloudbus.cloudsim.examples;/**Title:CloudSimToolkit*Description:CloudSim(CloudSimulation)Toolkitfor…

    2022年8月31日
    0
  • 大学生英语竞赛常考词汇汇总_全国大学生英语竞赛难吗

    大学生英语竞赛常考词汇汇总_全国大学生英语竞赛难吗abbreviation节略,缩写,缩短abidevi遵守,vt忍受absent不在意的abolishvt废除,取消abstracta理论上的,n抽象accessory同谋a附属的accord调和,符合,协议acknowledgevt承认,告知收到acquaintvt使认识,使了解adherevi黏附,追随,坚持adjoinvt贴近,毗连,靠近adjustablea.可调整的,可校准的administrationn局(或署、处等)

    2022年8月24日
    3
  • LBS定位技术「建议收藏」

    LBS定位技术「建议收藏」http://www.cnblogs.com/LBSer/p/3295642.htmlLBS定位技术从方法上可分成三类:基于三角关系的定位技术、基于场景分析的定位技术、基于临近关系的定位技术(唐毅和杨

    2022年8月2日
    3
  • 计算机技术与生物学的关系,生物信息学复习整理

    计算机技术与生物学的关系,生物信息学复习整理生信整理一、重要概念1.生物信息学的定义、研究内容、组成采用信息学的方法来研究生命科学定义:生物信息学迄今为止尚没有一个标准定义(广义:生命科学中的信息科学。生物体系和过程中信息的存贮、传递和表达;细胞、组织、器官的生理、病理、药理过程的中各种生物信息。狭义:生物分子信息的获取、存贮、分析和利用。)研究内容:①基础研究——数学:模型、算法;IT:数据库、计算机软、硬件开发②应用(生命科学研发)—…

    2022年7月11日
    15

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号