vue实现分页组件


Posted in Javascript onJune 16, 2020

本文实例为大家分享了vue实现分页组件的具体代码,供大家参考,具体内容如下

<template>
 <div class="pageBox">
 <ul>
  <li v-if="this.condition.pageNo > 1 && this.pages.length > 4" class="sides"><a @click="prePage()"><s class="font_main"></s></a></li>
  <li v-for="(item, index) in pages" :class="{'curtPage': condition.pageNo == item}">
  <a v-if="item" @click="goPage(item)" >
   <s>{{item}}</s>
  </a>
  <a href="javascript:;" rel="external nofollow" v-else>...</a>
  </li>
  <li class="sides" v-if="condition.pageNo < pageCount && this.pageCount > 4"><a @click="nextPage()"><s class="font_main"></s></a></li>
 </ul>
 </div>
</template>

js中代码 page 和condition是由父组件中传过来的参数

<script>
 export default {
 props: {
  page: Object,
  condition: Object
 },
 data () {
  return {
  pageSize: this.condition.pageSize
  }
 },
 computed: {
  pageCount: function () {
  return this.page.totalCount / this.condition.pageSize > 0 ? this.page.totalCount % this.condition.pageSize === 0 ? this.page.totalCount / this.condition.pageSize : Math.ceil(this.page.totalCount / this.condition.pageSize) : 1
  },
  pages () {
  let c = this.condition.pageNo
  let t = this.pageCount
  let arr = []
  if (t === 1) {
   return arr
  }
  if (t <= 4) {
   for (let i = 1; i <= t; i++) {
   arr.push(i)
   }
   return arr
  }
  if (c <= 3) return [1, 2, 3, 0, t]
  if (c >= t - 1) return [1, 0, t - 2, t - 1, t]
//  if (c === 4) return [1, 2, 3, 4, 5, 0, t]
//  if (c === (t - 2)) return [1, 0, t - 3, t - 2, t - 1, t]
  return [1, 0, c - 1, c, c + 1, 0, t]
  }
 },
 methods: {
  goPage (indexPage) {
  if (this.indexPage !== this.condition.pageNo) {
   this.condition.pageNo = indexPage
   this.$emit('search')
  }
  },
  prePage () {
  if (this.condition.pageNo !== 1) {
   this.condition.pageNo--
   this.goPage(this.condition.pageNo)
  }
  },
  nextPage () {
  if (this.condition.pageNo !== this.pageCount) {
   this.condition.pageNo++
   this.goPage(this.condition.pageNo)
  }
  }
 }
 }
</script>

效果图:

vue实现分页组件

vue实现分页组件

vue实现分页组件

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
multiSteps 基于Jquery的多步骤滑动切换插件
Jul 22 Javascript
Js中获取frames中的元素示例代码
Jul 30 Javascript
JS、CSS加载中的小问题探讨
Nov 26 Javascript
jQuery向上遍历DOM树之parents(),parent(),closest()之间的区别
Dec 02 Javascript
基于jQuery通过jQuery.form.js插件使用ajax提交form表单
Aug 17 Javascript
javascript实现根据函数名称字符串动态执行函数的方法示例
Dec 28 Javascript
扩展bootstrap的modal模态框-动态添加modal框-弹出多个modal框
Feb 21 Javascript
详解vuex结合localstorage动态监听storage的变化
May 03 Javascript
vue template中slot-scope/scope的使用方法
Sep 06 Javascript
JS中创建自定义类型的常用模式总结【工厂模式,构造函数模式,原型模式,动态原型模式等】
Jan 19 Javascript
uniapp与webview之间的相互传值的实现
Jun 29 Javascript
浏览器JavaScript调试功能无法使用解决方案
Sep 18 Javascript
如何用RxJS实现Redux Form
Dec 29 #Javascript
Vue.js结合bootstrap前端实现分页和排序效果
Dec 29 #Javascript
jQuery实现的鼠标拖动浮层功能示例【拖动div等任何标签】
Dec 29 #jQuery
javascript实现计算指定范围内的质数示例
Dec 29 #Javascript
基于vue.js组件实现分页效果
Dec 29 #Javascript
详解Vue.js v-for不支持IE9的解决方法
Dec 29 #Javascript
jQuery基于随机数解决中午吃什么去哪吃问题示例
Dec 29 #jQuery
You might like
CodeIgniter使用smtp服务发送html邮件的方法
2015/06/10 PHP
php实现遍历多维数组的方法
2015/11/25 PHP
CodeIgniter配置之config.php用法实例分析
2016/01/19 PHP
javascript call和apply方法
2008/11/24 Javascript
Javascript 汉字字节判断
2009/08/01 Javascript
关于setInterval、setTimeout在jQuery中的使用注意事项
2011/09/28 Javascript
jquery的ajax请求全面了解
2013/03/20 Javascript
基于jQuery的图片不完全按比例自动缩小
2014/07/11 Javascript
Javascript中的对象和原型(二)
2016/08/12 Javascript
使用grunt合并压缩js和css文件的方法
2017/03/02 Javascript
AngularJS表格添加序号的方法
2017/03/03 Javascript
微信小程序对接七牛云存储的方法
2017/07/30 Javascript
微信小程序之侧边栏滑动实现过程解析(附完整源码)
2019/08/23 Javascript
微信小程序实现左侧滑动导航栏
2020/04/08 Javascript
PyTorch线性回归和逻辑回归实战示例
2018/05/22 Python
利用Python进行数据可视化常见的9种方法!超实用!
2018/07/11 Python
24式加速你的Python(小结)
2019/06/13 Python
Pytorch修改ResNet模型全连接层进行直接训练实例
2019/09/10 Python
python conda操作方法
2019/09/11 Python
Python中低维数组填充高维数组的实现
2019/12/02 Python
深入理解Tensorflow中的masking和padding
2020/02/24 Python
python 日志模块logging的使用场景及示例
2021/01/04 Python
关于canvas绘制模糊问题的解决方法
2019/09/24 HTML / CSS
世界上最大的折扣香水店:FragranceNet.com
2016/10/26 全球购物
意大利奢侈品购物网站:Deliberti
2019/10/08 全球购物
生日邀请函范文
2014/01/13 职场文书
企业节能减排实施方案
2014/03/19 职场文书
产假请假条
2014/04/10 职场文书
交通局领导班子群众路线教育实践活动对照检查材料思想汇报
2014/10/09 职场文书
试用期自我评价范文
2015/03/10 职场文书
2015年度保密工作总结
2015/04/24 职场文书
放飞理想主题班会
2015/08/14 职场文书
MySQL Innodb关键特性之插入缓冲(insert buffer)
2021/04/08 MySQL
解决Vmware虚拟机安装centos8报错“Section %Packages Does Not End With %End. Pane Is Dead”
2022/06/01 Servers
mysql数据库如何转移到oracle
2022/12/24 MySQL