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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • C#移动端开发:获取用户定位和IP地址上传至SQL数据库

    C#移动端开发:获取用户定位和IP地址上传至SQL数据库文章为进阶栏目内容,详细解释可以看基础栏目这里使用的是

    2022年6月24日
    25
  • Java面试个人简历

    Java面试个人简历姓名:郑清求职意向:Java开发工程师专业技能:熟练使用Java面向对象编程,具有良好的编程习惯以及CSDN技术文档编写习惯;熟练使用Eclipse/IDEA等开发工具;熟练SVN,Maven,Git等项目管理工具;熟练Spring,SpringMVC,Hibernate,MyBatis等开源框架技术;掌握SpringBoot+SpringCloud微服务架构;掌握My…

    2022年7月9日
    17
  • strtok 函数

    strtok 函数C库函数-strtok()C标准库-<string.h>描述C库函数char*strtok(char*str,constchar*delim)分解字符串str为一组字符串,delim为分隔符。声明下面是strtok()函数的声明。char*strtok(char*str,constchar*delim)…

    2022年7月14日
    16
  • 为什么说 HashMap 是非线程安全的?

    点击上方☝Java编程技术乐园,轻松关注!及时获取有趣有料的技术文章做一个积极的人编码、改bug、提升自己我有一个乐园,面向编程,春暖花开!0. HashMap简单说几…

    2022年2月28日
    42
  • 贴片DO-218AB封装TVS二极管SM8T33A

    贴片DO-218AB封装TVS二极管SM8T33A提及“汽车级瞬态二极管”,大多数电子工程师都会想到DO-218AB封装SM8S系列中的SM8S24V、SM8S33A、SM8S36A、SM8S36CA等等,这些物料常用于汽车12V系统和24系统中,可通过抛负载7637-5a/5b测试,为汽车电子产品安全保驾护航。关于汽车级瞬态TVS二极管SM8T系列,知道的电子工程师并不多,但是经常有客户咨询:SM8T系列型号有哪些?SM8T33A二极管参数?SM8T36A可以替代SM8S36A吗?SM8T24CA和SM8S24CA有什么区别……瞬态二极管厂家东沃电子

    2022年9月23日
    0
  • 【网页设计的12种颜色】「建议收藏」

    前不久,ColourLovers.com公布了一项调查结果。他们发…

    2022年1月18日
    36

发表回复

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

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