≡
  • 网络编程
  • 数据库
  • CMS技巧
  • 软件编程
  • PHP笔记
  • JavaScript
  • MySQL
位置:首页 > 网络编程 > vue.js

vue实现分页组件

人气:585 时间:2019-04-16

这篇文章主要为大家详细介绍了vue实现分页组件,具有一定的参考价值,可以用来参考一下。

感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!

本文实例为大家分享了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>

效果图:

【图片暂缺】

【图片暂缺】

【图片暂缺】

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持四海网。

本文来自:http://www.q1010.com/184/7092-0.html

注:关于vue实现分页组件的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。

关键词:vue.js

您可能感兴趣的文章

  • 分析VUE里子组件如何获取父组件动态变化的值
  • axios携带cookie配置分析(axios+koa)
  • vue-router beforeEach跳转路由验证用户登录状态
  • Vue.js结合bootstrap前端实现分页和排序效果
  • 分析vuex commit保存数据技巧
  • Vuerouter的beforeEach与afterEach钩子函数的区别
  • 基于vue.js实现分页查询功能
  • highCharts提示框中显示当前时间的方法
  • 使用form-create动态生成vue自定义组件和嵌套表单组件
  • Vue核心概念Action的总结
上一篇:Mint UI实现A-Z字母排序的城市选择列表
下一篇:axios携带cookie配置分析(axios+koa)
热门文章
  • Vue 报错TypeError: this.$set is not a function 的解决方法
  • vue实现动态添加数据滚动条自动滚动到底部的示例代码
  • vue项目设置scrollTop不起作用(总结)
  • vue项目中使用vue-i18n报错的解决方法
  • iview实现select tree树形下拉框的示例代码
  • 分析关于element级联选择器数据回显问题
  • vue项目打包后打开页面空白解决办法
  • 解决element ui select下拉框不回显数据问题的解决
  • element-ui table span-method(行合并)的实现代码
  • element-ui 设置菜单栏展开的方法
  • 最新文章
    • 理解vue ssr原理并自己搭建简单的ssr框架
    • vue favicon设置以及动态修改favicon的方法
    • vue-router启用history模式下的开发及非根目录部署方法
    • 从零开始在NPM上发布一个Vue组件的方法步骤
    • Element input树型下拉框的实现代码
    • Vue 报错TypeError: this.$set is not a function 的解决方法
    • Vue.js组件高级特性实例分析
    • 浅谈VueJS SSR 后端绘制内存泄漏的相关解决经验
    • 分析Vue.js自定义tipOnce指令用法实例
    • 浅谈vuex actions和mutation的异曲同工

四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。