基于vue2.0的分页组件

来源:https://www.sucaihuo.com/js/3029.html 2017-09-17 22:20浏览(1901) 收藏

一款基于vue2.0的分页组件,可自由设置分页显示的多少、上一页、下一页等,也可以直接输入跳转到的页码再点击“GO”即可跳转,分页的样式可以自由调整。
基于vue2.0的分页组件
分类:其它特效 > 分页 难易:初级
查看演示 下载资源 下载积分: 20 积分
关注公众号,免费赠送安装视频教程、环境和学习视频,后面会不断更新。

页面的head部分,需设置好页面的样式,代码如下:

.page {
  font-weight: 900;
  height: 40px;
  text-align: center;
  color: #888;
  margin: 20px auto 0;
  background: #f2f2f2;
}

.pagelist {
  font-size: 0;
  background: #fff;
  height: 50px;
  line-height: 50px;
}

.pagelist span {
  font-size: 14px;
}

.pagelist .jump {
  border: 1px solid #ccc;
  padding: 5px 8px;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 5px;
}

.pagelist .bgprimary {
  cursor: default;
  color: #fff;
  background: #337ab7;
  border-color: #337ab7;
}

.jumpinp input {
  width: 55px;
  height: 26px;
  font-size: 13px;
  border: 1px solid #ccc;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
  text-align: center;
}

.ellipsis {
  padding: 0px 8px;
}

.jumppoint {
  margin-left: 30px;
}

.pagelist .gobtn {}

.bgprimary {
  cursor: default;
  color: #fff;
  background: #337ab7;
  border-color: #337ab7;
}

页面的body部分,在多个div的嵌套结果里面放入多个span标签来显示分页,代码如下:

<div id="app">
  <div>
    <div class="page"  v-show="show">
      <div class="pagelist">
        <span class="jump"v-show="current_page>1" @click="{current_page--}">上一页</span>
        <span v-show="current_page>5" class="jump" @click="jumpPage(1)">1</span>
        <span class="ellipsis"  v-show="efont">...</span>
        <span class="jump" v-for="num in indexs" :class="{bgprimary:current_page==num}" @click="jumpPage(num)">{{num}}</span>
        <span class="ellipsis"  v-show="efont&&current_page<pages-4">...</span>

        <span class="jump" @click="{current_page++}">下一页</span>
        <span v-show="current_page<pages-1" class="jump" class="jump" @click="jumpPage(pages)">{{pages}}</span>

        <span class="jumppoint">跳转到:</span>
        <span class="jumpinp"><input type="text" v-model="changePage"></span>
        <span class="jump gobtn" @click="jumpPage(changePage)">GO</span>
      </div>
    </div>
  </div>
</div>

页面的底部,需远程调用vue库,实例化分页并设置好相应的参数,代码如下:

<script type="text/javascript" src="http://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<script>
var newlist = new Vue({
  el: '#app',
  data: {
    current_page: 1, //当前页
    pages: 50, //总页数
    changePage:'',//跳转页
    nowIndex:0
  },
  computed:{
     show:function(){
         return this.pages && this.pages !=1
     },
     efont: function() {
       if (this.pages <= 7) return false;
       return this.current_page > 5
     },
     indexs: function() {

       var left = 1,
         right = this.pages,
         ar = [];
       if (this.pages >= 7) {
         if (this.current_page > 5 && this.current_page < this.pages - 4) {
           left = Number(this.current_page) - 3;
           right = Number(this.current_page) + 3;
         } else {
           if (this.current_page <= 5) {
             left = 1;
             right = 7;
           } else {
             right = this.pages;

             left = this.pages - 6;
           }
         }
       }
       while (left <= right) {
         ar.push(left);
         left++;
       }
       return ar;
     },
   },
  methods: {
    jumpPage: function(id) {
      this.current_page = id;
    },
  },
})
</script>
标签: 分页vue2.0
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2