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)
上一篇 2026年4月19日 下午8:37
下一篇 2026年4月19日 下午8:43


相关推荐

  • IDEA使用教程_超级cd使用教程

    IDEA使用教程_超级cd使用教程idea启动后会在cpan当前用户下生成一个C:\Users\Crystal.IntelliJIdea2018.1文件夹,这个文件夹里面有两个子文件夹config和system。删除这两个文件夹,idea在启动时候会重新配置。idea的project类似于eclipse的workspace;idea的modue类似于eclipse的project;配置都是在setti…

    2022年8月26日
    9
  • 现代 PHP 新特性系列(三) —— Trait 概览

    现代 PHP 新特性系列(三) —— Trait 概览

    2021年10月10日
    49
  • 2021年调味品行业发展的现状_2020年调味品行业所处阶段

    2021年调味品行业发展的现状_2020年调味品行业所处阶段2021年,受到需求收缩、成本上涨、预期转弱等因素叠加的影响,调味品行业发展面临巨大挑战,多数调味品上市公司发展趋缓。一、调味品上市公司经营现状2021年,16家调味品上市公司营业收入合计为871亿元,营业收入正增长的有12家,占16家上市公司的75%,其中营业收入排名前三位的公司分别是海天味业、梅花生物和安琪酵母,营业收入分别是250亿元、228.4亿元、106.8亿元,分别同比增长9.7%、33.9%、19.5%。2021年中国调味品上市公司营业收入及同比增长资料来源:中国调

    2025年6月15日
    6
  • 自监督学习详细介绍(学习笔记)

    自监督学习详细介绍(学习笔记)一、相关文献:fast.ai上面关于自监督学习的资料:Self-supervisedlearningandcomputervision.GitHub上面每年使用自监督学习的论文列表:AwesomeSelf-SupervisedLearning.相关微信推送二、自监督学习的介绍1.自监督学习的由来机器学习中基本的学习方法有:监督学习(supervisedlearning)、…

    2025年11月14日
    5
  • API之FindWindowEx和SendMessage

    API之FindWindowEx和SendMessage最近在VC6.0开发中碰到了两个函数,经过一番搜索查阅,特记录于此。

    2022年5月27日
    38
  • stimulsoft mysql_Stimulsoft Server

    stimulsoft mysql_Stimulsoft ServerStimulsoftReports.Server是一个客户服务器系统,允许您轻松、高效地使用报表实现完整的工作周期,包括从执行信息处理任务的设计和自动化到为用户准备便利的结果演示。快速和现代化的StimulsoftReports技术实现了报表模块的功能,并且灵活性和可靠性都经过了测试。StimulsoftReports.Server的特性概括:使用图形元素和不同的图表可以将通用数据源转换为明亮和…

    2022年7月26日
    7

发表回复

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

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