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%;"
相关推荐
0思必得021 分钟前
[Web自动化] Selenium处理动态网页
前端·爬虫·python·selenium·自动化
东东5161 小时前
智能社区管理系统的设计与实现ssm+vue
前端·javascript·vue.js·毕业设计·毕设
catino1 小时前
图片、文件的预览
前端·javascript
2501_920931702 小时前
React Native鸿蒙跨平台实现推箱子游戏,完成玩家移动与箱子推动,当所有箱子都被推到目标位置时,玩家获胜
javascript·react native·react.js·游戏·ecmascript·harmonyos
layman05283 小时前
webpack5 css-loader:从基础到原理
前端·css·webpack
半桔3 小时前
【前端小站】CSS 样式美学:从基础语法到界面精筑的实战宝典
前端·css·html
AI老李3 小时前
PostCSS完全指南:功能/配置/插件/SourceMap/AST/插件开发/自定义语法
前端·javascript·postcss
_OP_CHEN3 小时前
【前端开发之CSS】(一)初识 CSS:网页化妆术的终极指南,新手也能轻松拿捏页面美化!
前端·css·html·网页开发·样式表·界面美化
啊哈一半醒3 小时前
CSS 主流布局
前端·css·css布局·标准流 浮动 定位·flex grid 响应式布局
PHP武器库3 小时前
ULUI:不止于按钮和菜单,一个专注于“业务组件”的纯 CSS 框架
前端·css