前言
项目中使用 Table 表格 表头换行的问题
代码如下(示例):
//template
<el-table-column
label="测试名称特别长"
:render-header="labelHead"
align="center"
prop="name"
:show-overflow-tooltip="true"
>
<template slot-scope="scope">
<span>{{
scope.row.name== 0
? "男"
: scope.row.name== 1
? "女"
: ""
}}</span>
</template>
</el-table-column>
//methods
labelHead: function (h, { column, $index }) {
let l = column.label.length;
let f = 12;
column.minWidth = f * (l + 2); //加上一个文字长度
return h("div", { class: "table-head", style: { width: "100%" } }, [
column.label,
]);
},
总结: show-overflow-tooltip 当内容过长被隐藏移上显示 表头表体都可以用。