zoukankan      html  css  js  c++  java
  • VUE BOOTSTRAP分页组件

    <template>
        <div id="pagenation" class="row justify-content-center">
            <div class="col-auto">
                <ul v-if="pagenation.total>pagenation.pageSize" class="pagination ">
                    <li class="page-item">
                        <a href="javascript:void(0);" @click="startPage" class="page-link">首页</a>
                    </li>
                    <li v-for="i in displayPage"
                        :key="'pagenation_'+i" :class="pagenationItemActive(i)">
                        <a href="#" @click="selectPage(i)" class="page-link">{{i}}</a>
                    </li>
                    <li class="page-item ">
                        <a href="javascript:void(0);" @click="endPage" class="page-link">尾页</a>
                    </li>
                </ul>
            </div>
            <div class="col-auto  mb-3">
                <div class="input-group" style=" 150px">
                    <input type="text" class="form-control" :placeholder="jumpPageNumPlaceholder" v-model.number="jumpPageNum">
                    <div class="input-group-append">
                        <button @click="jumpPageClick" @blur="jumpPageBlur" class="input-group-text">跳转</button>
                    </div>
                </div>
            </div>
        </div>
    </template>
     
    <script>
        export default {
            name: "Pagenation",
            data() {
                return {
                    jumpPageNum: '',
                    jumpPageNumPlaceholder: '跳转到...'
                }
            },
            props: {
                pagenation: Object,
                // pagenation: {
                //     total: 22,
                //     pageSize: 10,
                //     pageNum: 1,
                // },
     
                pageNumChange: Function,
            },
            computed: {
                displayPage() {
                    let totalPage = this.pagenation.total % this.pagenation.pageSize === 0 ? (parseInt(this.pagenation.total / this.pagenation.pageSize)) : (parseInt(this.pagenation.total / this.pagenation.pageSize) + 1)
                    let pageNum = this.pagenation.pageNum;
                    if (totalPage < 10) {
                        return totalPage;
                    } else {
                        let arr = []
                        if (pageNum < 5) {
                            for (let i = 1; i <= 10; i++) {
                                arr.push(i)
                            }
                        } else if (pageNum >= totalPage - 5) {
                            for (let i = totalPage - 9; i <= totalPage; i++) {
                                arr.push(i)
                            }
                        } else {
                            for (let i = pageNum - 4; i <= pageNum + 5 && i < totalPage; i++) {
                                arr.push(i)
                            }
                        }
                        return arr
                    }
                }
            },
            watch: {
                'pagenation.pageNum'(newValue, oldValue) {
                    console.log(newValue, oldValue)
                    this.pageNumChange(newValue, oldValue)
                },
            },
            methods: {
                pagenationItemActive(i) {
                    if (i == this.pagenation.pageNum) {
                        return 'page-item active'
                    } else {
                        return 'page-item'
                    }
                },
                selectPage(pageNum) {
                    this.pagenation.pageNum = pageNum
                },
                startPage() {
                    if (this.pagenation.pageNum !== 1) {
                        this.pagenation.pageNum = 1
                    }
                },
                endPage() {
                    let totalPage = this.pagenation.total % this.pagenation.pageSize === 0 ? (parseInt(this.pagenation.total / this.pagenation.pageSize)) : (parseInt(this.pagenation.total / this.pagenation.pageSize) + 1)
                    if (this.pagenation.pageNum !== totalPage) {
                        this.pagenation.pageNum = totalPage
                    }
                },
                jumpPageBlur() {
                    this.jumpPageNumPlaceholder = '跳转到...'
                },
                jumpPageClick() {
                    let regex = /^[0-9]+$/;
                    if (regex.test(this.jumpPageNum)) {
                        let jumpPageNum = parseInt(this.jumpPageNum)
                        if (jumpPageNum > 0 && jumpPageNum <= (this.pagenation.total % this.pagenation.pageSize === 0 ? (parseInt(this.pagenation.total / this.pagenation.pageSize)) : (parseInt(this.pagenation.total / this.pagenation.pageSize) + 1))) {
                            this.pagenation.pageNum = jumpPageNum
                        } else {
                            this.jumpPageNumPlaceholder = '超出范围'
                        }
                    } else {
                        this.jumpPageNumPlaceholder = '输入错误'
                    }
                    this.jumpPageNum = '';
                }
            }
        }
    </script>
    <style scoped>
    </style>
    

      

  • 相关阅读:
    0108 创建表约束
    Mybatis 将数据库中查出的记录,一对多返回,即分组,然后返回每个组的所有数据
    SQL主表、从表
    MySQL中添加、删除字段,使用SQL语句操作
    git 将远程工作分支合并到本地dev分支
    MySQL inner join 和 left join 的区别
    Mysql union 和 order by 同时使用需要注意的问题
    The used SELECT statements have a different number of columns
    Every derived table must have its own alias(MySQL报错:每个派生表都必须有自己的别名)
    MySQL 日期格式化及字符串、date、毫秒互相转化
  • 原文地址:https://www.cnblogs.com/helloworld3/p/11192397.html
Copyright © 2011-2022 走看看