Element表格无限滚动

页面部分

<template>
                <el-table
                  :header-cell-style="rowClass"
                  :cell-style="cellStyle"
                  :data="courseRankingCensusData"
                  height="100%"
                  style="width: 90%"
                  highlight-current-row
                  ref="rolltable"
                  @mouseenter.native="stopScroll"
                  @mouseleave.native="startScroll"
                >
                  <el-table-column
                    type="index"
                    label="使用排名"
                    width="100"
                    style="color: white"
                  >
                    <template> </template>
                  </el-table-column>
                  <el-table-column label="课程名" width="100">
                    <template slot-scope="scope">
                      <div>
                        {{ scope.row.mode }}
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column label="形式" width="100">
                    <template slot-scope="scope">
                      <div>
                        {{ scope.row.name }}
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column label="使用率" width="100">
                    <template slot-scope="scope">
                      <div>
                        {{ scope.row.ratio }}
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </template>

主要是用到ref="rolltable" 来去做效果

 这是:data="courseRankingCensusData" 里面 courseRankingCensusData接收的数据

这是methods里面的代码

 startScroll() {
      this.tableScroll(false);
      
    },
    stopScroll() {
      this.tableScroll(true);
      
    },

    tableScroll(stop) {
      if (stop) {
        clearInterval(this.rolltimer);
        return;
      }
      const table = this.$refs.rolltable;
      const divData = table.bodyWrapper;
      let index = 0;
      this.rolltimer = setInterval(() => {
        // console.log(table.tableData.length ,844);
        divData.scrollTop += 160;
        index += 100;
        // console.log(index,84888);
        // if (divData.clientHeight + divData.scrollTop + 1 >divData.scrollHeight) {
        //   if (table.tableData.length > this.courseRankingCensusDatalength) {
        //     divData.scrollTop = 0;
        //   }
        // }
        if (index >= 600) {
          divData.scrollTop = 0;
          index = 0;
          // console.log('重新');
          // this.tableScroll(false);
        }
      }, 1000);
    },

需要在data中定义 rolltimer 要不会报错

在mounted里面的代码

 this.tableScroll(false);

效果不太好但是可以用 不需要引入任何插件

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值