vue.js 简单分页案例(1)

这是一个翻页的简单实例,把案例在本地运行一下,然后去理解每行的意思
样式

ul,li{
    margin: 0px;
    padding: 0px;
}
li{
    list-style: none
}
.page-bar li:first-child>a {
   margin-left: 0px
}
.page-bar a{
    border: 1px solid #ddd;
    text-decoration: none;
    position: relative;
    float: left;
    padding: 6px 12px;
    margin-left: -1px;
    line-height: 1.42857143;
    color: #337ab7;
    cursor: pointer
}
.page-bar a:hover{
    background-color: #eee;
}
.page-bar .active a{
    color: #fff;
    cursor: default;
    background-color: #337ab7;
    border-color: #337ab7;
}
.page-bar i{
    font-style:normal;
    color: #d44950;
    margin: 0px 4px;
    font-size: 12px;
}

html代码

<div class="page-bar">
<ul>
<li v-if="showFirst"><a v-on:click="cur--">上一页</a></li>
<li v-for="index in indexs"  v-bind:class="{ 'active': cur == index}">
    <a v-on:click="btnClick(index)">{{ index }}</a>
    </li>
<li v-if="showLast"><a v-on:click="cur++">下一页</a></li>
<li><a>共<i>{{all}}</i>页</a></li>
</ul>
</div>

javascrit代码

var pageBar = new Vue({
el: '.page-bar',
data: {
    all: 20, //总页数
    cur: 1,//当前页码
 },
  methods: {
        btnClick: function(data){//页码点击事件
            if(data != this.cur){
                this.cur = data 
            }
        }
  },
  computed: {
          showLast: function(){
               console.log(1);
                if(this.cur == this.all){
                    return false
                }
                return true
           },
           showFirst: function(){
               console.log(2);
                if(this.cur == 1){
                    return false
                }
               return true
           },
        indexs: function(){
          var left = 1
          var right = this.all
          var ar = [] 
          if(this.all>= 11){
            if(this.cur > 5 && this.cur < this.all-4){//大于6并且小于16
                    left = this.cur - 5
                    right = this.cur + 4
            }else{
                if(this.cur<=5){
                    left = 1
                    right = 10
                }else{
                    right = this.all
                    left = this.all -9
                }
            }
         }
        while (left <= right){
            ar.push(left)
            left ++
        } 
        return ar
       }
       
    },
           
});
    
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值