element table 表头固定,表格高度自适应

//通过 :height="tableHeight" 设置
<el-table>
  :height="tableHeight"
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        class="tab_info"
        style="width: 100%"
        default-expand-all
        row-key="id"
        :row-class-name="tableRowClassName"
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        @selection-change="handleSelectionChange"
        v-loading="loading"
</el-table>
export default {
    
    
  data() {
    
    
      return {
    
    
tableHeight:500 , // 自己设置高度
            }
      },
  mounted() {
    
    
    //固定表头
    this.$nextTick(function() {
    
    
      this.tableHeight =
        window.innerHeight - this.$refs.table.$el.offsetTop - 50;

      // 监听窗口大小变化
      let self = this;
      window.onresize = function() {
    
    
        self.tableHeight =
          window.innerHeight - self.$refs.table.$el.offsetTop - 50;
      };
    });
  },
}

猜你喜欢

转载自blog.csdn.net/weixin_42342065/article/details/128330950