elementui实现数据懒加载

模拟前台数据

<el-table  v-loading="loading" :data="tableData" ref="myTable"  :show-header="false" height="7.15rem" style="width: 100%">
        <el-table-column width="60">
          <template slot-scope="scope">
            <img src="../../assets/images/onemapNew/地裂缝_一般.png" v-if="scope.row.type_info==='normal'&& scope.row.dic_disaster_type1==='groundCrack'">
            <img src="../../assets/images/onemapNew/地裂缝_重要.png" v-if="scope.row.type_info==='important'&& scope.row.dic_disaster_type1==='groundCrack'">
            <img src="../../assets/images/onemapNew/地面塌陷_一般.png" v-if="scope.row.type_info==='normal'&& scope.row.dic_disaster_type1==='groundCollapse'">
            <img src="../../assets/images/onemapNew/地面塌陷_重要.png" v-if="scope.row.type_info==='important'&& scope.row.dic_disaster_type1==='groundCollapse'">
            <img src="../../assets/images/onemapNew/崩塌_一般.png" v-if="scope.row.type_info==='normal'&& scope.row.dic_disaster_type1==='collapse'">
            <img src="../../assets/images/onemapNew/崩塌_重要.png" v-if="scope.row.type_info==='important'&& scope.row.dic_disaster_type1==='collapse'">
            <img src="../../assets/images/onemapNew/滑坡_一般.png" v-if="scope.row.type_info==='normal'&& scope.row.dic_disaster_type1==='landslide'">
            <img src="../../assets/images/onemapNew/滑坡_重要.png" v-if="scope.row.type_info==='important'&& scope.row.dic_disaster_type1==='landslide'">
          </template>
        </el-table-column>
        <el-table-column>
          <template slot-scope="scope">
            <div>名称:{{scope.row.name}}</div>
            <div>灾害类型:{{scope.row.dic_disaster_name}}</div>
            <div>威胁人数:{{scope.row.threat_num}}&#12288&#12288威胁财产:{{scope.row.threat_value}}万元</div>
            <div style="display: flex; flex-direction: row;justify-content: flex-end;">
              <el-button size="mini" style="padding: 5px" type="primary" @click="headClick(scope.row)">开始巡查</el-button>
              <el-button size="mini" style="padding: 5px" type="primary" @click="headTodayClick(scope.row)">巡查记录</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>

获取table相关dom数据

 onloadData(){
      let that = this;
      let dom = that.$refs.myTable.bodyWrapper;
      dom.addEventListener("scroll", function() {
        const scrollDistance =dom.scrollHeight - dom.scrollTop - dom.clientHeight;
        console.log(scrollDistance)
        if(scrollDistance <=0){//等于0证明已经到底,可以请求接口
          if(that.pageNum < that.currentPage){//当前页数小于总页数就请求
            this.pageNum++;//当前页数自增
            let params={
              uuid:that.userinfo.uuid,
              regioncode: that.userinfo.regioncode,
              token: that.userinfo.token,
              pagenum:that.pageNum,
              pagesize:that.pageSize,
              keywords: that.valueSearch
            }
            getwarndaily(params).then(res=>{
              if (res.code===200000){
                that.currentPage=res.data.count
                that.tableData = that.tableData.concat(res.data.data)//将请求回来的数据和当前展示的数据合并在一起
                that.loading=false
              }else{
                that.loading=false
              }
            }).catch(err=>{
              console.log(err)
              that.loading=false
            })

          }
        }
      })
    },
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小仙有礼了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值