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


相关推荐

  • 函数模板与同名的非模板函数不可以重载(重载的定义)

    关于函数的重载机制,是一个比较复杂的问题,其中涉及到了优先级定义和最佳匹配等问题,如果要阐述清楚,恐怕不是一两篇文章就能说的明白。但是如果掌握了一些常用的“规律”,对于了解程序对重载函数是如何进行选择也有很大的好处,本文尝试将自己理解的知识,结合下面简单的例子简略的说说函数重载机制,文章的摘录部分列出了一些关于程序如何选择重载函数的规则。:)例子如下:#include

    2022年4月15日
    102
  • linux获取时间戳_java时间戳转换成时间

    linux获取时间戳_java时间戳转换成时间转换成指定的日期格式,如“2021/08/2919:25:18‘:date-d@1630236318+”%Y/%m/%d%H:%M:%S”leon@ubuntu:~/work$date-d@1630236318+”%Y/%m/%d%H:%M:%S”2021/08/2911:25:18date-d@1630236318leon@ubuntu:~/work$date-d@1630236318Sun29Aug202111:25:18AMUTC…

    2022年10月2日
    3
  • 股票 数据接口(股票行情数据接口)

    最近股票大跌,打算做点数据分析。转个数据接口,等我完成数据分析有具体结论再写出来吧。做了一点股票分析数据准备,做了个均线图:http://stock.chenpeng.info/randomone查询股票走势请移步:http://stock.chenpeng.info/,搜索请输入代码或者股票名称。Sina股票数据接口eg:http://hq.sinajs.cn/li…

    2022年4月14日
    60
  • 基于情感词典的情感分析_情感计算和情感分析

    基于情感词典的情感分析_情感计算和情感分析原理我就不讲了,请移步下面这篇论文,包括情感词典的构建(各位读者可以根据自己的需求稍作简化),以及打分策略(程序对原论文稍有改动)。论文在这里下载:基于情感词典的中文微博情感倾向性研究-陈晓东-华中科技大学(大家可以上百度学术搜索下载)本文采用的方法如下:首先对单条微博进行文本预处理,并以标点符号为分割标志,将单条微博分割为n个句子,提取每个句子中的情感词。以下两步的处理均以…

    2022年8月23日
    8
  • PHP error_reporting() 错误控制函数功能详解

    PHP error_reporting() 错误控制函数功能详解

    2021年9月19日
    51
  • ViewPager 详解(五)—–使用Fragment实现ViewPager滑动[通俗易懂]

    ViewPager 详解(五)—–使用Fragment实现ViewPager滑动[通俗易懂]前言:前几篇文章讲解了ViewPager的普通实现方法,但android官方最推荐的一种实现方法却是使用fragment,下面我们使用fragment来重新实现一下第一篇《ViewPager详解(一)—基本入门》所实现的效果。系列文章:1、《ViewPager详解(一)—基本入门》2、《ViewPager详解(二)—详解四大函数》3、《ViewPage…

    2022年7月22日
    21

发表回复

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

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