Vue Emlment-ui安装,el-pagination分页的使用

一、安装element-ui:参考http://element-cn.eleme.io/#/zh-CN/component/installation

二、项目中引入
在main.js中添加如下代码
这里写图片描述

三、分页的使用,先看代码 el-pagination 分页组件
解释 :
1.background 有——添加页码背景框 / 默认没有——没有背景
2.pager-count 最多显示的页码数,多余部分在中间“…”代替
3.total 总条数
4.layout 设置需要显示的内容:包括总页数,上一页/下一页图标,页码,前往 XX 页【可自由配置】

<template>
  <div id="box">
    <div style="font-size: 24px;color: white;margin-bottom: 20px">用户打卡记录</div>
    <ul>
      <li v-for="item in clockInfoList">
        <div><span style="width: 80px;display: inline-block">{{item.userName}}</span><span style="margin-left: 20px">{{item.date}}</span>
        </div>
        <div style="color: white">{{item.address}}</div>
      </li>
    </ul>
    <div>
      <!-- 分页控件 layout中的jumper布局有问题,这里没用-->
      <el-pagination
        class="pageView"
        v-if="paginationShow"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageNo"
        :page-size="15"
        layout="total, prev, pager, next"
        :pager-count="11"
        :total="totalCount">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import http from '../../../http/httpRequestUtil'
  import store from '../../../store/index'

  export default {
    name: "UserClockInfo",
    data() {
      return {
        clockInfoList: [],//返回数据——填充到数据列表
        pageSize: store.state.pageSize,//默认的请求pageSize = 15
        pageNo: 1,//当前页码
        totalPage: 0,//总页数
        paginationShow: false,//是否显示分页
        totalCount: 0,//总条数
      }
    },
    methods: {
      //改变每页显示数量时调用
      handleSizeChange(val) {
        this.$nextTick(() =>
          this.getPageData(),
        )
      },
      //点击下一页和点击页码时执行
      handleCurrentChange(val) {
        this.getPageData();
      },
      //获取分页数据totalDataNumber
      getPageData: function () {
        let that = this;
        let reqUrl = "api-common/clock/toAppList?pageSize=" + this.pageSize + "&page=" + parseInt(this.pageNo)
        http.getData(reqUrl, function (clockInfoList, message) {
          console.log(clockInfoList)
          if (clockInfoList != null) {
            that.clockInfoList = clockInfoList.result;
          }
        })
      }
    },
    //进入页面后请求的初始数据
    created: function () {
      let that = this;
      let reqUrl = "api-common/clock/toAppList?pageSize=" + this.pageSize + "&page=1"
      http.getData(reqUrl, function (clockInfoList, message) {
        console.log(clockInfoList)
        if (clockInfoList != null) {
          that.clockInfoList = clockInfoList.result;
          that.totalPage = clockInfoList.totalPage;//设置分页的总页数
          that.totalCount = clockInfoList.totalCount;//设置数据总条数
          if (clockInfoList.totalPage > 1) {//总页数大于1时显示分页
            that.paginationShow = true;
          }
          console.log("总页数:" + that.totalPage)
        }
      })
    }
  }
</script>

<style scoped>
  #box {
    padding: 20px;
  }

  ul {
    padding: 0px;
    list-style-type: none;
  }

  li {
    margin-top: 5px;
    color: yellow;
    font-size: 20px;
    border-bottom: 1px white dashed;
  }

  .pageView {
    height: 30px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
  }
</style>

四、展示效果
这里写图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值