240
正在加载今日诗词....

ElementUI 表格自适应高度终极解决方案

直接上代码,这样不管在表格上边有任何组件,都可以解决。下边的这个50高度是用来放其他组件的,比如常见的分页组件,如果你不需要的话,可以不用放。

  this.$nextTick(function () {
    //在页面渲染完成后
    this.height = window.innerHeight - this.$refs.table.$el.getBoundingClientRect().top - 50     
    this.$refs.table.$el.getBoundingClientRect().top //表格距离浏览器的高度
    var that = this
    // 添加监听窗口大小变化事件
    window.onresize = function () {
      that.height = window.innerHeight - that.$refs.table.$el.getBoundingClientRect().top - 50
    }
  })
posted @ 2022-03-13 01:41  小鱼吃猫  阅读(618)  评论(0编辑  收藏  举报