el-table固定表头,表格自适应

通过el-table的height固定:

    附官网链接:https://element.eleme.cn/#/zh-CN/component/table

el-table固定表头,表格自适应_第1张图片

 代码如下

//通过 :height="tableHeight" 设置

  :height="tableHeight"
        ref="table"
        :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"

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;
      };
    });
  },
}

el-table固定表头,表格自适应_第2张图片

 

你可能感兴趣的:(elementui,vue)