vue设置元素自动充满(页面高度-其它元素的高 || 页面高度-距离顶部的高度-底部元素的高度)

复制代码
<template>
  <div class="app-container">
  <el-row class="search" ref="tip">第一个模块</el-row>
  <el-row class="search" ref="elForm">第二个模块</el-row>
  <el-row class="table" ref="tableList">
    表格模块
  </el-row>
  </div>
</template>
复制代码
复制代码
<script>
export default {
  name: "UserInfo",
 ...
  methods: { 
    // 表格高度
    getHeight() {
      // TODO 计算元素的高度和上边距,后面可能会用到
      // 获取高度值 (内容高+padding+边框)
      // let tipHeight = this.$refs.tip.$el.offsetHeight // div高度
      // let tipTop = this.$refs.tip.$el.offsetTop // div距离上边距高度
      // let formHeight = this.$refs.elForm.$el.offsetHeight // 表单高度
      // let elFormTop = this.$refs.elForm.$el.offsetTop // 表单距离上边距高度
      let tableTop = this.$refs.tableList.$el.offsetTop // 表上边距的高度
      let bottomHeight = 20 //  尾部高度固定的

      this.tableHeight = window.innerHeight - tableTop - bottomHeight - 15; // 15像素是为了计算出来的数据默认和底部有15像素的边距
    },
  },
beforeMount() {
    // 滚动条的获取
    window.addEventListener('resize', this.getHeight)
  },
  mounted() {
    this.$nextTick(() => { // 页面渲染完成后的回调
      this.getHeight()
    })
  },
}
复制代码

 


 
 
posted @   骑蝴蝶飞  阅读(1475)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· winform 绘制太阳,地球,月球 运作规律
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示