ElementUI表格el-table自适应高度(表头表尾固定不动)

ElementUI表格el-table自适应高度(表头表尾固定不动),内容只在中间滚动,效果如图:

实现代码

html 复制代码
<div class="mt-10" :style="{'height':tableHeight}">
      <div class="operation-bar">
        <el-button :icon="Plus" @click="allSave()" v-if="isEdit == 1">保存</el-button>
        <el-button @click="exportTable()">导出Excel</el-button>
      </div>
			<el-table :data="data" border style="width: 100%;font-size: 12px;height:90%;" v-loading="loading" @cell-click="cellClick" :cell-class-name="AddClass">
				<el-table-column  type="index" width="40" label="序号" fixed="left"></el-table-column>
				<el-table-column prop="SalaryMonth" label="发放年月" width="95" fixed="left"></el-table-column>
				<el-table-column prop="Departmentname" label="部门" width="150" fixed="left"></el-table-column>
				<el-table-column prop="WorkCompanyName" label="劳务公司" width="150" fixed="left"></el-table-column>
				<el-table-column prop="UserName" label="姓名" width="80" fixed="left"></el-table-column>
				<el-table-column prop="CertificateName" label="员工编号" width="80" fixed="left"></el-table-column>
				<el-table-column prop="PostTitle" label="证件号码" width="170" fixed="left"></el-table-column>
        <el-table-column :prop="FillSetID" :label="item.FillSetName" width="100" v-for="(item ,i) in setdata" align="center">
          <template #default="scope">
            <el-input
                v-model="scope.row[item.FillSetID]"
                @blur="removeClass(scope.row[item.FillSetID], scope.$index, scope.row)"
                type="number"
                v-if="isEdit == 1"/>
            <span >{{ scope.row[item.FillSetID] }}</span>
          </template>
        </el-table-column>
				<el-table-column label="备注">
          <template #default="scope">
            <el-input
                v-model="scope.row.Remark"
                @blur="removeClass(scope.row.Remark, scope.$index, scope.row)"
                type="text"
                v-if="isEdit == 1"/>
            <span >{{ scope.row.Remark }}</span>
          </template>
        </el-table-column>
			</el-table>
			<el-pagination background layout="total, prev, pager, next, jumper, sizes" :total="total" v-model:current-page="page" v-model:page-size="pageSize" class="pagination" @current-change="pageChange" />
		</div>

使用JS动态获取窗口高度

javascript 复制代码
data(){
 return{
  tableHeight: window.innerHeight + 'px'
 }
}
复制代码
<div class="mt-10" :style="{'height':tableHeight}"> vue绑定变量

需要给el-table 加上高度样式

复制代码
<el-table :data="data" border style="width: 100%;font-size: 12px;height:90%;"
相关推荐
子兮曰6 小时前
OpenClaw入门:从零开始搭建你的私有化AI助手
前端·架构·github
吴仰晖6 小时前
使用github copliot chat的源码学习之Chromium Compositor
前端
1024小神6 小时前
github发布pages的几种状态记录
前端
不像程序员的程序媛8 小时前
Nginx日志切分
服务器·前端·nginx
Daniel李华8 小时前
echarts使用案例
android·javascript·echarts
北原_春希8 小时前
如何在Vue3项目中引入并使用Echarts图表
前端·javascript·echarts
JY-HPS8 小时前
echarts天气折线图
javascript·vue.js·echarts
尽意啊8 小时前
echarts树图动态添加子节点
前端·javascript·echarts
吃面必吃蒜8 小时前
echarts 极坐标柱状图 如何定义柱子颜色
前端·javascript·echarts
O_oStayPositive8 小时前
Vue3使用ECharts
前端·javascript·echarts