• 超简单的vue2.0分页组件


    1.组件代码

    <template>
        <div class="pagination_comment_style" style=" 100%;overflow: hidden">
            <ul class="pagination">
                <li @click="goPage(pageIndex-1)" v-bind:class="{ 'no-allow': 1 == pageIndex }"><span>«</span></li>
                <li @click="goPage(item)" v-for="item in pages" v-bind:class="{ 'active': item == pageIndex }"><span>{{item}}</span></li>
                <li @click="goPage(pageIndex+1)" v-bind:class="{ 'no-allow': pageIndex == pageLength }" style="border-right: none;"><span>»</span></li>
            </ul>
            <div style="float: left;line-height: 32px;height: 32px;font-size: 14px;
            margin-left: 20px;color: #666;">跳转到
                <input v-model="goIndex" style=" 30px;height: 30px;border: 1px solid #ddd;border-radius: 5px;text-align: center;margin-left: 5px;" type="text">
                <span style="display: inline-block;height: 30px; 30px;border-radius: 5px;background-color: #428BCA;color: #fff;
                text-align: center;cursor: pointer;" @click="goPage(goIndex)">GO</span></div>
            <div style="float: left;line-height: 32px;height: 32px;color: #666;font-size: 14px;margin-left: 30px;">
                第 {{pageIndex}} 条 / 共 {{pageLength}} 条
            </div>
        </div>
    </template>
    <script>
        export default {
            props:['pageIndex','pageLength'],
            data () {
                return {
                    goIndex:''
                }
            },
            computed: {
                pages(){
                    var _  = this,pages=[],length,pageIndex = parseInt(_.pageIndex),pageLength=parseInt(_.pageLength);
                    if(pageIndex<5){
                        length = pageLength>7?8:pageLength+1
                        for (var i = 1;i<length;i++) pages.push(i)
                    }else if(pageIndex>4){
                        if(pageLength-pageIndex>2){pages.push(pageIndex-3);pages.push(pageIndex-2);pages.push(pageIndex-1);
                            pages.push(pageIndex);pages.push(pageIndex+1);pages.push(pageIndex+2);pages.push(pageIndex+3);
                        }else {
                            length = pageLength>7?pageLength-7:0
                            for (var i = pageLength;i>length;i--)pages.push(i)
                            pages.reverse();
                        }
                    }
                    return pages
                }
            },
            watch: {},
            methods: {
                goPage(index){
                    index = parseInt(index)
                    if(index<1|| index>this.pageLength) return
                    this.$emit('goPage',index)
                }
            },
            created(){
    
            },
            components: {}
        }
    </script>
    <style>
        .pagination_comment_style .pagination{display: inline-block;overflow: hidden;border-radius: 5px;border: 1px solid #ddd;float: left}
        .pagination_comment_style .pagination li{float: left; 32px;height: 32px;line-height: 32px;text-align: center;
            border-right: 1px solid #ddd;cursor: pointer;color: #666;font-size: 14px;}
        .pagination_comment_style .pagination li:not(.no-allow):hover,.pagination_comment_style .pagination li.active{background-color: #eee;}
        .pagination_comment_style .pagination li.no-allow:hover{cursor:  not-allowed;}
    </style>
    

      

    2.引入组件

       <pagination
                @goPage="goPage"
                :pageIndex='info.index'
                :pageLength='info.length'
            ></pagination>
    
        //goPage(index)  跳转某一页,index 要去的页码
        
        //pageIndex 当前页码
    
        //pageLength 总页数
    

      

    代码仅供参考,具体功能可以自己扩展。

    个人博客 :精华所在   https://gilea.cn/

    http://www.cnblogs.com/jiebba    我的博客,来看吧!

  • 相关阅读:
    JDBC基本入门-JDBC中各个接口和类详解
    Docker 安装与基本使用
    java打包和运行的方式
    使用@Valid+BindingResult进行controller参数校验
    Antd使用timePicker封装时间范围选择器(React hook版)
    antd的table组件设置Column的width列宽度不生效问题
    vector二维数组如何排序
    递归反转链表(通俗详解)
    安装pythorch出现“由于目标计算机积极拒绝,无法连接”问题
    C语言字符串
  • 原文地址:https://www.cnblogs.com/jiebba/p/7147197.html
Copyright © 2020-2023  润新知