Vue2:el-table 最后一列的操作按钮不换行,按钮过多时展示【更多】
表格中最后一列为操作按钮。有时候按钮比较多,就会换行展示,将行高撑大,很难看。所以需要控制按钮都显示在同一行,如果太多显示不下,出现一个下拉列表。
1、flex 布局来控制按钮的显示
设置 display: flex
来将按钮放在同一行,设置 white-space: nowrap
来禁止换行。
<el-table-column label="操作">
<template slot-scope="scope">
<div style="display: flex; white-space: nowrap;">
<!-- 这里可以放置操作按钮的代码 -->
</div>
</template>
</el-table-column>
2、将其它按钮放在el-dropdown 组件中
click触发
<el-table-column label="操作">
<template slot-scope="scope">
<div style="display: flex; white-space: nowrap;">
<el-button>按钮1</el-button>
<el-button>按钮2</el-button>
<el-button>按钮3</el-button>
<el-dropdown trigger="click" style="margin-left: 10px">
<el-button slot="default" type="text">更多</el-button>
<el-dropdown-menu slot="default">
<el-dropdown-item>按钮4</el-dropdown-item>
<el-dropdown-item>按钮5</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</template>
</el-table-column>