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

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    <style>
    a{display:inline-block;margin:0 5px;height:20px;color:#666;background:#eee;text-decoration:none;padding:0 10px;text-align:center;line-height:20px;background:#ccc}
    a.active{background:#008B8B;color:#fff}
    </style>
    </head>
    <body>
    <div id="app">
    <page-component :pageCount="page.pageCount" :pagesize="page.pageSize" :pageIndex="page.pageIndex" @getdata='getData' @get="getPage"></page-component>
    </div>
    </body>
    <script src="//cdn.bootcss.com/vue/2.1.10/vue.js"></script>
    <script>
    Vue.component('page-component',{
    props:['pagecount','pageindex','pagesize'],
    data () {
    return {
    current:this.pageindex,
    showItem:this.pagesize,
    allPage:this.pagecount
    }
    },
    template:`
    <div class="page">
    <a href="javascript:" v-show="current != 1" @click="current-- && goto(current)">上一页</a>
    <a href="javascript:" v-for="index in pages" :class="{active:(index == current)}" @click="goto(index)" :key="index">{{index}}</a>
    <a href="javascript:" v-show="current != allPage && allPage!= 0" @click="current++ && goto(current)">下一页</a>
    </div>
    `,
    computed:{
    pages:function(){
    var pag = [];
    if( this.current < this.showItem ){ //如果当前的激活的项 小于要显示的条数
    //总页数和要显示的条数那个大就显示多少条
    var i = Math.min(this.showItem,this.allPage);
    while(i){
    pag.unshift(i--);
    }
    }
    else
    { //当前页数大于显示页数了
    var middle = this.current - Math.floor(this.showItem / 2 ),//从哪里开始
    i = this.showItem;
    if( middle > (this.allPage - this.showItem) ){
    middle = (this.allPage - this.showItem) + 1
    }
    while(i--){
    pag.push( middle++ );
    }
    }
    return pag
    }
    },
    methods:{
    goto:function(index){
    this.current =index;
    this.$emit('get',index)
    this.$emit('getdata')
    }
    }
    });

    new Vue({
    el:'#app',
    data:{
    page:{
    pageCount:10, //总页数
    pageIndex:1, //默认页
    pageSize:5 //每次显示页数
    }
    },
    methods:{
    getPage:function(inx){
    this.page.pageIndex = inx;
    },
    getData:function(){
    alert("这里面写请求第"+this.page.pageIndex+"页数据");

    //这里面执行ajax请求的分页信息
    }
    }
    })
    </script>
    </html>

  • 相关阅读:
    jquery判断复选框是否选中
    jquery验证网址格式
    jquery右下角返回顶部
    thinkphp分页格式的完全自定义,直接输入数字go到输入数字页
    textarea出现多余的空格
    html渐隐轮播
    linux 路由 route
    ansible 自动化运维工具
    数据库 group by 后其他列的取值
    linux 磁盘io高排查
  • 原文地址:https://www.cnblogs.com/zywaf/p/7090212.html
Copyright © 2011-2022 走看看