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


相关推荐

  • java中strictfp关键字,java strictfp关键字用法大全详解

    java中strictfp关键字,java strictfp关键字用法大全详解一、strictfp关键字简介strictfp是Java中提供的一个保留关键字,该关键字是从这第javaJDK2版本儿开始出现的一直沿用到现在,只不过很多情况下都不怎么使用,所以容易被大家遗忘,因此今天我们来介绍一下这个关键字的用法和使用详解案例。strictfp实际上是对浮点类型做精确运算的一个关键字,实际意思是FP-strictfp,Java中的浮点类型有float和double两种,当这两…

    2025年7月24日
    3
  • android之如何在两个activity之间传递handler_利用broadcast广播机制「建议收藏」

    这算是如何在两个activity之间传递handler的解决方案二了,解决方案一见http://blog.csdn.net/jason0539/article/details/18055259再重复一遍我遇到的问题,就是在MainActivity里面打开AnotherActivity去执行一些操作,相应的改变MainActivity里的一些布局或者执行一些动作,最开始想到的就是把MainAct

    2022年3月11日
    53
  • select into from 与 insert into select用法详解

    select into from 与 insert into select用法详解selectintofrom和insertintoselect都被用来复制表结构和表中数据,两者的主要区别为:selectintofrom要求目标表不存在,因为在插入时会自动创建。insertintoselectfrom要求目标表已存在数据库中。一、INSERTINTOSELECT语句  1、语句形式为:

    2022年7月15日
    19
  • 一篇读懂无线充电技术(附方案选型及原理分析)「建议收藏」

    一篇读懂无线充电技术(附方案选型及原理分析)「建议收藏」一文读懂无线充电技术(附方案选型及原理分析)0.背景1.无线供电特点2.无线供电原理及实现方式3.现有解决方案分析4.FAQ及相关测试5.参考资料0.背景现今几乎所有的电子设备,如手机,MP3和笔记本电脑等,进行充电的方式主要是有线电能传输,既一端连接交流电源,另一端连接便携式电子设备充电电池的。这种方式有很多不利的地方,首先频繁的插拔很容易损坏主板接口,另外不…

    2022年5月7日
    51
  • iOS app测试_测试插件app

    iOS app测试_测试插件app前言1、准备开发者账号自从Xcode7出来之后,一般的真机测试不需要开发者账号,也就不需要看这篇教程,只有app具有“推送”等功能的时候,要真机测试就必须要开发者账号和设置证书。苹果只是让你体验一下它的基本功能,要深入还是要花钱的。待测试的项目2、真机测试步骤1)创建AppID2)创建证书请求文件(CSR文件)3)根据CSR创建开发者证书(C…

    2025年9月21日
    7
  • 图像基础知识之YUV

    图像基础知识之YUV一、YUV常用格式YUV是编译true-color颜色空间(colorspace)的种类,Y'UV,YUV,YCbCr,YPbPr等专有名词都可以称为YUV,彼此有重叠。“Y”表示明亮

    2022年7月1日
    29

发表回复

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

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