vue + elementUi中el-table表格高度自适应

699 阅读1分钟

首先html里设置table的高度

<el-table ref="recordTable" :data="tableData" border :height="tableHeight">
<el-table>
data(){
	return {
		tableHeight: 50 //默认初始值
	}
}

根据浏览器高度设置初始高度,并监听浏览器高度变化,改变表格高度,70表示表格距离浏览器的高度

mounted(){
    this.$nextTick(() =>{
      // 根据浏览器高度设置初始高度
      this.tableHeight = window.innerHeight - this.$refs.recordTable.$el.offsetTop - 70
      // 监听浏览器高度变化,改变表格高度
      window.onresize = () =>{
        this.tableHeight = window.innerHeight - this.$refs.recordTable.$el.offsetTop - 70
      }
    })
  },

方法来自:
www.cnblogs.com/muou2125/p/…