zoukankan      html  css  js  c++  java
  • Element UI ——table 动态添加数据滚动条一直处于最下方

    代码:

    // table表格
    <el-table ref="TestTable" :data="DataList">
            <el-table-column prop="no" label="序号" width="80"></el-table-column>
    </el-table>
    
    
    // 获取数据
    queryStudent() {
          getStudent().then((response) => {
            const tempList = this.DataList;
            this.DataList = tempList.concat(response.data.List);
            this.$nextTick(()=>{
              this.$refs.TestTable.bodyWrapper.scrollTop = this.$refs.DataList.bodyWrapper.scrollHeight;
            })
        }
    }
    

    原理:

      el-table里有个bodyWrapper  它指向的是el-table的表格内容部分,存在 scrollTop,scrollHeight 属性,所以可以用下面方法来实现滚动条在底部的效果

      table需设置ref表格属性,例如:TestTable

      this.$nextTick() 是为了让表格加载完再执行,不加上可能会看不到效果

      如果要在不同屏幕下表格高度需要适应屏幕的话,需要用到 window.onresize 函数

      

    window.onresize = () => {
        this.caseListHeight = window.innerHeight - 405;
    }
    

      

      一般JS表格滚动条置于最下方用法(未测试)

    let table = document.getElementById('id名字');
    table.scrollTop = table.scrollHeight;
    

      

      来源:https://blog.csdn.net/yx_cos/article/details/94589135

  • 相关阅读:
    c语言指针讲解第一节初识指针
    linux的的一些入门常识
    sql手注的思路
    mysql主从备份配置
    CentOS 6.5 nginx+tomcat+ssl配置
    mysql 5.7.18安装教程
    minIO分布式集群搭建+nginx负载均衡
    Linux常用命令
    使用python连接mysql数据库——pymysql模块的使用
    with与上下文管理器
  • 原文地址:https://www.cnblogs.com/lucky-jun/p/15044234.html
Copyright © 2011-2022 走看看