码迷,mamicode.com
首页 > 其他好文 > 详细

elementui的table与自适应高度

时间:2019-11-25 11:05:56      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:姓名   自适应高度   offset   created   适应   省份   代码   自适应   nbsp   

element官方文档中的table高度都是用的

height="250"

来定义了table固定高度,实际中很多时候我们需要使表格来自适应某个div,所以height一般不能让它为一个固定高度,下面看代码

<div ref="tableCot">
    <el-table
    :data="tableData"
    style="width: 100%"
    :height="Height">
    <el-table-column
      fixed
      prop="date"
      label="日期"
      width="150">
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="120">
    </el-table-column>
    <el-table-column
      prop="province"
      label="省份"
      width="120">
    </el-table-column>
    <el-table-column
      prop="city"
      label="市区"
      width="120">
    </el-table-column>
  </el-table>
</div>

需要注意的是定义一个Height与高度绑定,然后是script中的操作

在data里面先定义一个Height

data(){
  return{
        Height:250
    }  
}
mounted () {
    const that = this
    window.onresize = () => {
      return (() => {
        let heightStyle = that.$refs.tableCot.offsetHeight
        that.Height = heightStyle
      })()
    }
  },
created () {
    let that = this
    let heightStyle = that.$refs.tableCot.offsetHeight
    that.Height = heightStyle
  },

就OK了这里监听的div变化是windows窗口的变化,如果某些操作会使tableCot大小发生变化,那需要在那个事件上加上

let heightStyle = that.$refs.tableCot.offsetHeight
this.Height = heightStyle

 

elementui的table与自适应高度

标签:姓名   自适应高度   offset   created   适应   省份   代码   自适应   nbsp   

原文地址:https://www.cnblogs.com/daicw/p/11926308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!