折腾了很久,尝试了各种方式,最后好像弄出来了,先给表格增加的head和cell添加固定的class:pg-cell和pg-header-cell,然后在这两个class中添加不换行的样式,再将el-table的table-layout设为auto:
<div class="pg-box">
<el-table :data="pgdata.data" style="width: 100%" height="100%" class="pg-table"
:cell-class-name="'pg-cell'"
:header-cell-class-name="'pg-header-cell'"
fit="true"
table-layout="auto">
<!-- 这里是列 -->
</el-table>
</div>
<style>
.pg-cell .cell{
word-break: keep-all !important;
white-space: nowrap !important;
}
.pg-header-cell .cell{
word-break: keep-all !important;
white-space: nowrap !important;
}
</style>