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


相关推荐

  • linux源码分析(二)-启动过程

    linux源码分析(二)-启动过程

    2022年3月12日
  • Laravel – 验证码(captcha)

    Laravel – 验证码(captcha)

    2021年10月26日
  • noip2015_noip2021复赛

    noip2015_noip2021复赛二项式定理推出系数等于a^n*b^m*C(n,k)快速幂+组合数(逆元做除法)结束。具体看代码:#include&lt;iostream&gt;#include&lt;cstdio&gt;#include&lt;cstring&gt;#include&lt;string&gt;#include&lt;algorithm&gt;#include&lt;vector&gt;#inc…

    2022年9月25日
  • jdk下载与安装[通俗易懂]

    1.JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html安装完成后,需要进行环境变量的配置,右键我的电脑—属性—-高级系统设置就会看到下面的界面:2.点击环境变量,开始坏境变量的配置:(1)点击系统变量下的新建按钮,变量名JAVA_HOME(代表你的JDK安装路径),值对应的是你的JDK的安装路径。(2)继续在系统变量里面新建一个CLASSPATH变量,其变量值如下图所示:….

    2022年4月3日
  • 银河麒麟安装windows虚拟机_中标麒麟安装vmtools

    银河麒麟安装windows虚拟机_中标麒麟安装vmtools下载系统:http://download.cs2c.com.cn/neokylin/desktop/releases/6.0/x86_64/iso/安装系统:1.新建虚拟机,选择典型,下一步2.稍后安装操作系统,下一步3.选择Linux系统版本为其他Linux3.x内核,下一步4.设置磁盘大小为…

    2022年8月10日
  • json对象转map对象_json map

    json对象转map对象_json map1.jsonObject转map相关jar包:importjava.util.HashMap;importjava.util.Iterator;importjava.util.Map;importjava.util.Map.Entry;importcom.alibaba.fastjson.JSON;importcom.alibaba.fastjson.JSONObject;代码:JSONObjectuser=resJson.getJSONObj

    2022年8月23日

发表回复

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

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