整体满屏,表格高度auto

该代码段展示了一个Vue.js组件中如何根据窗口大小和内部元素高度动态调整容器及表格的高度。在created钩子中监听窗口resize事件,调用onResize方法重新计算高度。onResize方法计算了body高度、外层盒子和内层盒子的偏移量,以确定新的containerHeight和tableHeight。
摘要由CSDN通过智能技术生成

1.页面

ref="changeBox" :style="{ 'height': containerHeight + 'px' }"
ref="table"  :height="tableHeight" :max-height="tableHeight" 
ref="pageBox"
<template>
  <div class="orderInfo" ref="changeBox" :style="{ 'height': containerHeight + 'px' }">
    <el-table :data="tableData" border id="outExcel" ref="table" v-loading="tableLoading" row-key="id" stripe
      :height="tableHeight" :max-height="tableHeight" size="medium" style="width:100%;"> 
    </el-table>
    <div class="pageInfo" ref="pageBox">
    </div>
  </div>
</template>
data() {
    return {
      containerHeight: 800,
      tableHeight: 500,
    }
  },
  created() {
    this.$nextTick(function () {
      this.onResize();
    });
    window.addEventListener('resize', this.onResize);
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.onResize);
  },
  methods: {
   onResize() {
      this.$method.onResize(this.$refs.changeBox, this.$refs.pageBox);
      this.containerHeight = this.$method.containerHeight;
      this.tableHeight = this.$method.tableHeight;
    },
    }

2.js

export default {
  containerHeight:500,
  tableHeight:500,
  // 根据滚动条高显示的大小发生变化
  onResize(outerBox,innerBox) {
    var boxHeight = document.documentElement.clientHeight || document.body.clientHeight;
    var mapTop = outerBox.getBoundingClientRect().top;
    var pageHeight = innerBox.getBoundingClientRect().height;
    this.containerHeight = boxHeight - mapTop - 40;
    this.tableHeight = this.containerHeight - pageHeight;
  },
  
}

3.main.js

import method from "@/util/public";
Vue.prototype.$method = method;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值