el-dialog中el-table实现自适应

示例代码

<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自适应

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值