Vue实现web分页组件详解

前端之家收集整理的这篇文章主要介绍了Vue实现web分页组件详解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

效果演示

代码

<Meta charset="UTF-8"> 测试<a href="https://www.jb51.cc/tag/fenye/" target="_blank" class="keywords">分页</a> - www.maoyupeng.com

<script src="https://unpkg.com/vue/dist/vue.js"&gt;
<script type="text/javascript">
var app = new Vue({
el: '#app',data: {
// 省略的符号
sign:'...',// 省略号位置
signIndex:4,// 总页数
totalPageCount: 4,// 当前页
currentPage:1,// 显示页面的数组列表
pagingList:[]
},watch: {
totalPageCount (val) {
var that = this
if (!val || val == '') return;
that.currentPage = 1;
that.init()
},currentPage (val) {
var that = this
that.init()
}
},methods: {
// 跳转到某页码
next (num) {
var that = this
if (num <= 1) that.currentPage = 1;
else if (num >= that.totalPageCount) that.currentPage = that.totalPageCount;
else that.currentPage = num;
},// 初始化数据
fetchData () {
var that = this

that.pagingList = [];
var tmp = null;


if ((that.totalPageCount) > 6) {
 if (((that.totalPageCount-1) == (that.totalPageCount - that.currentPage)) && (that.totalPageCount - that.currentPage) > 5) {
  for (var i=1;i<7;i++) {
   if (i < that.signIndex) {
    tmp = {key:i,value:i }
   } else if (i== that.signIndex) {
    tmp = {key:that.sign,value:0 }
   } else if (i == (that.signIndex + 1) ) {
    tmp = {key:that.totalPageCount - 1,value:that.totalPageCount - 1 }
   } else {
    tmp = {key:that.totalPageCount,value:that.totalPageCount }
   }
   that.pagingList.push(tmp)
  }
 } else if (((that.totalPageCount - that.currentPage) <= that.signIndex)){
  var starNum = that.totalPageCount - 5;
  for (var i=starNum;i<starNum+6;i++) {
   tmp = {key:i,value:i }
   that.pagingList.push(tmp)
  }
 } else {
  var starNum = that.currentPage - 1;
  for (var i=1;i<7;i++) {
   if (i < that.signIndex) {
    tmp = {key:(starNum - 1) + i,value:(starNum - 1) + i }
   } else if (i== that.signIndex) {
    tmp = {key:that.sign,value:that.totalPageCount }
   }
   that.pagingList.push(tmp)
  }
 }
} else {
 for (var i =0; i <that.totalPageCount; i++) {
  tmp = {key:i+1,value:i+1 }
  that.pagingList.push(tmp)
 }
}

},init () {
var that = this

that.fetchData()

}
},mounted () {
var that = this

that.init()
}
})

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

原文链接:https://www.f2er.com/vue/34984.html

猜你在找的Vue相关文章