VUE2.0 ElementUI2.0表格el-table自适应高度的实现方法

2020-06-14 05:54:10易采站长站整理

在开发中,需要表格控件根据浏览器高度进行调整,固定表头,且然后多余的出滚动条,官方给出的:

只要在el-table元素中定义了height属性,即可实现固定表头的表格,而不需要额外的代码。

然后直接上template代码:


<template>
<el-table
:data="tableData3"
height="250"
border
style="width: 100%">
<el-table-column
prop="date"
label="日期"
width="180">
</el-table-column>
</el-table>
</template>

其中height=”250″是固定值,我们可以在data中设置一个tableHeight,其中x是根据你布局自己算出来的值,也可以换成动态监测的值,就是父级到body的值,这个可以自行添加


data(){
return{
tableHeight: window.innerHeight - x
}
}

template中:


<template>
<el-table
:data="tableData3"
:height="tableHeight"
border
style="width: 100%">
<el-table-column
prop="date"
label="日期"
width="180">
</el-table-column>
</el-table>
</template>