JavaScript

超轻量级php框架startmvc

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

更新时间:2020-08-06 21:24 作者:startmvc
在开发中,需要表格控件根据浏览器高度进行调整,固定表头,且然后多余的出滚动条,官

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

只要在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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。