Vue结合Element UI中的分页从封装到页面使用

Vue结合Element中的分页,从封装到页面使用。

分页一直让人捉摸不透,今天上班正好遇到了,就自己封装了一个分页,方便以后使用,也发出来我们一起使用。互相学习吧。

大概样式就是这样的。
在这里插入图片描述
那么接下来就直接上代码吧!
封装组件页面,命名为page4.vue

<template>
<div id="pagination" v-if="total>10">
    <span @click="currentchange(1)" class="btn">首页</span>
    <el-pagination
    layout="prev, pager, next"
    :total="total"
    prev-text="上一页"
    next-text = "下一页"
    @current-change="currentchange"
    @prev-click="prevclick"
    @next-click="nextclick"
    :current-page.sync="currentpage"
    :background="bg"
    >
  </el-pagination>
  <span @click="lastclick" class="btn">尾页</span>
</div>

</template>

js部分:

<script>
export default {
  props:{
    total:{
      type:Number,
      default:1
    },
    bg:{
      type:Boolean,
      default:true
    },
    pagenumber:{
      type:Number,
      default:0
    }

  },
data(){
    return{
      currentpage:null,
      lastpage:null,
    }
  },
  watch:{
      pagenumber(e){
        this.currentpage = e
      }
    },
  methods:{
    // 首页
    currentchange(i){
      this.currentpage = i,
      this.$emit("getpage",i)

    },
    //上一页
    prevclick(i){
      this.$emit("getpage",i)
    },
    //下一页
    nextclick(i){
      this.$emit('nextpage',i)
    },
    //尾页
    lastclick(){
            this.lastpage = this.total/10
            if(this.total%10 == 0){
              this.currentpage = this.lastpage
            }else{
              this.currentpage = math.ceil(this.lastpage)
            }
              this.$emit("getpage",this.currentpage)
            }
    },
  }
</script>

css部分《用的是less写的》:

<style lang="less" scoped>
#pagination{
  margin: 20px 30px 0px 0px;
  text-align: right;
  .el-pagination.ia-background.el-pager li{
    background: #ffffff;
  }
  .el-paginatin .is-background .el-page li :not(.disabled).cative{
    color: blue;
  }
  .el-page .el-background .btn-next{
    background: #ffffff;
  }
  .el-page .el-background .btn-prev{
    background: #ffffff;
  }
  .span{
    font-size: 14px;
    vertical-align: middle;
    cursor: pointer;
  }
  .el-pagination{
    display: inline-block;
    vertical-align: middle;
  }
  .btn{
    vertical-align: middle;
    display: inline-block;
    width: 60px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border-radius: 4px;
  }
}
</style>

既然封装好方法了,那么就直接可以在页面使用了,引入封装好的组件。 创建一个fenye.vue页面

<fenye.vue>

<template>
   <div>
     <el-pagination @getpage = "getpage" :total="total"></el-pagination>
   </div>
</template>

js代码:

<script>
import paginatin from "./Page4"
export default {
  
    data(){
        return{
            total:1,
            pageNume:1,
        }
    },
    created(){
        this.getList()
    },
    components:{
        paginatin
    },
    methods:{
        getpage(e){
            this.page = e;
            this.getList()
        },
        getList(){
            this.$axios.post("",{

            }).then((res)=>{
                console.log(res)
            })
        }
    }
}
</script>

样式可以根据页面的位置自己来调整!在这里我就不多写了^ _ ^

特此感谢大家的观看,我们一起进步!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值