el-table 根据屏幕大小 动态调整max-height 的值

<template>
  <div>
    <p>窗口高度:{{ windowHeight }} px</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
       // 下面的 -250  表示减去一些表单元素高度 这个值需要自己手动调整
      windowHeight: document.documentElement.clientHeight - 250, // 初始化窗口高度
    };
  },
  methods: {
    updateWindowHeight() {
      // 更新窗口高度
      this.windowHeight = document.documentElement.clientHeight;
      console.log("窗口高度变化为:", this.windowHeight);
    },
  },
  mounted() {
    // 组件挂载后添加事件监听器
    window.addEventListener("resize", this.updateWindowHeight);
  },
  beforeDestroy() {
    // 组件销毁前移除事件监听器
    window.removeEventListener("resize", this.updateWindowHeight);
  },
};
</script>

<style scoped>
/* 添加样式 */
</style>

如果你不考虑 屏幕缩放的自动调整高度 那就可以用下面的 

      <el-table
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        :max-height="tableHeight"
        border
        stripe
        :header-cell-style="{
          background: '#f1f3f5',
          color: '#000000'
        }"
      >

      </el-table>


  computed: {
    tableHeight () {
    // 下面的 - 262  表示减去一些表单元素高度 这个值需要自己手动调整
      return document.documentElement.clientHeight - 262
    }
  },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值