首先在table上绑定ref
<template>
<el-table
ref="tableRef"
:data="tableData"
style="width: 100%">
<el-table-column
prop="date"
label="日期"
width="180">
</el-table-column>
</el-table>
</template>
然后在this.$nextTick()里获取ref进行更改
this.$nextTick(()=>{
this.$refs.tableRef.$el.style.cssText="height"+(this.tableData.length+1*48)+"px;max-height:"+height+"px"
})
this.tableData.length 是接口获取回来的数据的条数+1 乘以 一条数据的高度,就是表格的高度。
max-height:是表格超过一个固定高度以后滚动条显示
这样表格高度就可以自适应了
个人vuepress搭建博客链接