ElementUi分页组件碰到的问题

在使用elementui分页组件时,碰到用了组件后,分页的功能都正常实现,但是页面渲染的数据并不是按照所要求的每页显示5条或者10条来显示。

分析原因:

el-table获取的数据应当是已经做好处理的数据,而不是从后端拿到的整体数据

以下为代码

<template>
  <div id="app">
    <el-table :data="tableData" style="width: 100%" border ref="multipleTable" @select="selectRow">

      <el-table-column  type="selection" width="55"></el-table-column>

      <el-table-column prop="userId" label="用户编号" width="180"></el-table-column>

      <el-table-column prop="userName" label="用户名" width="180"></el-table-column>

      <el-table-column prop="userMale" label="性别" width="180"></el-table-column>

        <el-table-column prop="headImage" label="头像" >
          <template slot-scope="scope">
            <el-image
                :src='scope.row.headImage'
                style="width: 80px; height: 50px"
            ></el-image>
          </template>
        </el-table-column>


      <el-table-column prop="userBirthday" label="用户生日"></el-table-column>

      <el-table-column prop="userAddress" label="用户地址"></el-table-column>

    </el-table>
    <div style="margin-top: 20px">
      <el-button @click="toggleSelection()">取消选择</el-button>
     </div>
    <div class="block">
      <span class="demonstration">调整每页显示条数</span>
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-sizes="[5,10,15,20,25,30]"
          :page-size="pageSize"
          layout="total,sizes,prev, pager, next,jumper"
          :total="userMessage.length">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "userInfo",
  data(){
    return {
      currentPage:1,
      pageSize:10,
      tableData:''
    }
  },
  methods:{
    //每页的条数
    handleSizeChange(val){
      this.pageSize = val
      this.getPageDate()
      console.log('每页的数据',this.getPageDate())
      console.log(`每页${val}条`)
      console.log('每页显示的记录数',this.pageSize)
    },
    handleCurrentChange(val){
      this.currentPage = val
      this.getPageDate()
      console.log(`当前页${val}`)
      console.log('每页的页码显示',this.currentPage)
    },
    getPageDate(){
      //计算分页数据的起始位置
      // eslint-disable-next-line no-unused-vars
      let start = (this.currentPage - 1)*this.pageSize
      //计算分页数据的结束位置
      let end = start + this.pageSize
      //获取分页数据  this.userMessage.slice(start,end) 每页需要渲染的条数
      this.tableData = this.userMessage.slice(start,end)
      // console.log('分页数据',this.tableData)
    },
    //
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    selectRow(selection,row){
      console.log('row',selection,row)
      let u_id = ''
      for(let user of selection){
        u_id += user.userId+','
      }
      u_id = u_id.substring(0,u_id.length-1)
      console.log(u_id)
    },
    getuserInfo(){
      this.$http.get('/api/find').then(res=>{
        console.log(res)
        this.tableData = res.data
      }).catch(e=>{
        console.log(e)
      })
    }
  },
  computed:{
    userMessage(){
      return this.$store.getters.getUserList
    }
  },
  created() {
      this.$store.dispatch('getUserList')
    this.getuserInfo()
  }
}
</script>

<style scoped>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值