示例代码
<style>
.el-dialog {
display: flex;
flex-direction: column;
width: 90%;
height: 90%;
margin: 0 5% !important;
}
.el-dialog__header {
height: 5%;
}
.el-dialog__body {
height: 95%;
padding: 0 2%;
}
.el-dialog__wrapper {
display: flex;
justify-content: center;
flex-direction: column;
}
</style>
<div id="container">
<el-dialog title="title" :visible.sync="dialogVisible"
width="90%" height="100%">
<div style="display: flex; width: 100%; height: 100%">
<div style="height: 25%; width: 50%; padding: 0 1%; display: flex; flex-direction: column;">
<el-table
:data="tableData"
stripe
border
height="100%"
v-loading="loading">
<el-table-column
prop="prop1"
min-width="50%"
label="label">
</el-table-column>
<el-table-column
prop="prop2"
min-width="25%"
label="label">
</el-table-column>
<el-table-column
prop="prop3"
min-width="25%"
label="label">
</el-table-column>
</el-table>
</div>
<div style="width: 50%; padding: 0 1%;"></div>
</div>
</el-dialog>
</div>
el-dialog内部元素自适应
el-dialog
中的el-table
无法实现自适应布局,试了很久dialog
本身的高度就是无视项目侧边栏等直接取到全屏高度。el-table
想在其中设定百分比是无效的。
首先修改dialog为flex布局
<style>
.el-dialog {
display: flex;
flex-direction: column;
width: 90%;
height: 90%;
margin: 0 5% !important;
}
.el-dialog__header {
height: 5%;
}
.el-dialog__body {
height: 95%;
padding: 0 2%;
}
.el-dialog__wrapper {
display: flex;
justify-content: center;
flex-direction: column;
}
</style>
el-table 自适应高宽
el-table
外的div要是height: 100%
,再补充一个div在el-table
外部设置宽度和高度就可改变el-table
的高和宽.
<div style="height: 25%; width: 50%; padding: 0 1%; display: flex; flex-direction: column;">
<el-table
:data="tableData"
stripe
border
height="100%"
v-loading="loading">
<el-table-column
prop="prop1"
min-width="50%"
label="label">
</el-table-column>
<el-table-column
prop="prop2"
min-width="25%"
label="label">
</el-table-column>
<el-table-column
prop="prop3"
min-width="25%"
label="label">
</el-table-column>
</el-table>
</div>
el-table
中的列宽可以使用min-width
设置以实现 el-table自适应