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%;"
相关推荐
万叶学编程3 小时前
Day02-JavaScript-Vue
前端·javascript·vue.js
前端李易安4 小时前
Web常见的攻击方式及防御方法
前端
PythonFun5 小时前
Python技巧:如何避免数据输入类型错误
前端·python
知否技术5 小时前
为什么nodejs成为后端开发者的新宠?
前端·后端·node.js
hakesashou5 小时前
python交互式命令时如何清除
java·前端·python
天涯学馆5 小时前
Next.js与NextAuth:身份验证实践
前端·javascript·next.js
HEX9CF5 小时前
【CTF Web】Pikachu xss之href输出 Writeup(GET请求+反射型XSS+javascript:伪协议绕过)
开发语言·前端·javascript·安全·网络安全·ecmascript·xss
ConardLi5 小时前
Chrome:新的滚动捕捉事件助你实现更丝滑的动画效果!
前端·javascript·浏览器
ConardLi5 小时前
安全赋值运算符,新的 JavaScript 提案让你告别 trycatch !
前端·javascript