element table高度自适应

 时间:2024-10-15 08:18:20

1、自定义一个table的高度tableHeight

2、<el-table @row-click="lookDetail" v-loadmore="loadMore" v-loading="listLoading" :data="tableData" :height="tableHeight" border style="width: 100%"> <el-table-column :key="item.prop" v-for="item in tableColumn" :prop="item.prop" :label="item.name"> </el-table-column> </el-table>

3、data中给tableHeight一个默认的高度tableHeight: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight - 240,(这里的240是减去表格上面导航和搜索条件的高度)

4、在mounted中初始化数据mounted() { const that = this window.onresize = () => { return (() => { window.tableHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight that.tableHeight = window.tableHeight - that.$refs.queryHeight.offsetHeight - 150 })() } },

5、在watch中监听高度的变化watch: { // 这里的定时器是为了优化,如果频繁调用window.onresize方法会造成页诹鬃蛭镲面卡顿,增加定时器会避免频繁调用window.onresize方法 timer默认值设置为false,这里相当于一个按钮,防止频繁改变时引起卡顿 tableHeight(val) { if (!this.timer) { this.tableHeight = val this.timer = true const that = this setTimeout(function() { that.timer = false }, 400) } } },

  • 至尊魔都正式版1.4.0攻略装备升级合成
  • 怎样通过Run Away的LEVEL 56?
  • 随申办怎么切换到长者模式
  • 怎样让Skype在后台时显示通话窗口
  • 王者荣耀cat现在在哪个战队
  • 热门搜索
    清明节手抄报内容文字 妇女节手抄报 廉洁文化进校园手抄报 民法典手抄报 手抄报大全 国学经典手抄报 有趣的汉字手抄报 关于诗歌的手抄报 中国梦手抄报内容 端午节手抄报资料