• vue.js实现一个简单的分页


    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta charset="utf-8">
    <title></title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <script type="text/javascript" src="vue.min.js"></script>
    <style>
    .page-bar{
        margin:40px;
    }
    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 a.banclick{
        cursor:not-allowed;
    }
    .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;
    }
    </style>
    </head>
    <body>
     <div class="page-bar">
        <ul>
            <li v-if="cur>1"><a v-on:click="cur--,pageClick()">上一页</a></li>
            <li v-if="cur==1"><a class="banclick">上一页</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="cur!=all"><a v-on:click="cur++,pageClick()">下一页</a></li>
            <li v-if="cur == all"><a class="banclick">下一页</a></li>
            <li><a><i>{{all}}</i></a></li>
        </ul>
    </div>
    <script type="text/javascript">
    var pageBar = new Vue({
        el: '.page-bar',
        data: {
            all: 20, //总页数
            cur: 1//当前页码
        },
        watch: {
            cur: function(oldValue , newValue){
                console.log(arguments);
            }
        },    
         methods: {
            btnClick: function(data){//页码点击事件
                if(data != this.cur){
                    this.cur = data 
                }
            },
            pageClick: function(){
                console.log('现在在'+this.cur+'');
            }
        },
        
        computed: {
            indexs: function(){
              var left = 1;
              var right = this.all;
              var ar = [];
              if(this.all>= 5){
                if(this.cur > 3 && this.cur < this.all-2){
                        left = this.cur - 2
                        right = this.cur + 2
                }else{
                    if(this.cur<=3){
                        left = 1
                        right = 5
                    }else{
                        right = this.all
                        left = this.all -4
                    }
                }
             }
            while (left <= right){
                ar.push(left)
                left ++
            }
            return ar
           }
             
        }
    })
    </script>
    </body>
    </html>
  • 相关阅读:
    Java编程规范
    java 编程军规
    数据库编程军规条例
    过滤重复记录(因为关联扩展表)
    根据子部门获取其到根部门的路径
    (原创)defparam的应用(Verilog,CPLD/FPGA)
    (原创)学习MCU的感悟_初级(MCU,经验)
    (原创)基于FPGA的调光流水灯(Verilog,CPLD/FPGA)
    (原创)基于MCU的频率可调,占空比可调的PWM实现(MCU,MCS-51/MSP430)
    (原创)动物照的情感与角度拍摄(摄影,欣赏)
  • 原文地址:https://www.cnblogs.com/qxh-beijing2016/p/12644047.html
Copyright © 2020-2023  润新知