有时候如果table的header的内容太多而页面的宽度有限,这个时候需要将多长的文字隐藏起来,显示省略号并用弹窗显示全部信息,这时候可以使用render-header这个属性,自定义生成header,看下面的代码:文章来源:https://www.toymoban.com/news/detail-776035.html
<template>
<div class="table-contain">
<el-table :data="tableData" border style="width: 100%">
<el-table-column prop="date" label="Date" width="180">
</el-table-column>
<el-table-column prop="name" label="Name" width="180">
</el-table-column>
<el-table-column
prop="address"
label="This is a long long long long long long long long long long Address"
:render-header="renderHeader"
>
</el-table-column>
</el-table>
</div>
</template>
<script>
export default {
name: "elementTable",
data() {
return {
tableData: [
{
date: "2016-05-03",
name: "Tom",
address: "No. 189, Grove St, Los Angeles",
},
{
date: "2016-05-02",
name: "Tom",
address: "No. 189, Grove St, Los Angeles",
},
{
date: "2016-05-04",
name: "Tom",
address: "No. 189, Grove St, Los Angeles",
},
{
date: "2016-05-01",
name: "Tom",
address: "No. 189, Grove St, Los Angeles",
},
],
};
},
created() {
let _this = this;
},
mounted() {
let _this = this;
},
components: {},
methods: {
renderHeader: function (h, { column }) {
return h(
"div",
{
slot: "content",
class: "table-header-flex",
},
[
h(
"el-tooltip",
{
props: {
placement: "top",
},
},
[
h(
"div",
{
slot: "content",
style: {
whiteSpace: "normal",
},
},
column.label
),
h(
"span",
{
style: {
whiteSpace: "normal",
overflow: "hidden",
"text-overflow": "ellipsis",
"white-space": "nowrap",
"max-width": "90%",
display: "inline-block",
},
},
column.label
),
]
),
]
);
},
},
};
</script>
<style>
.table-contain{
width: 500px;
height: 100%;
padding: 10px;
}
</style>
上面代码中renderHeader方法里要注意column 包含的是每一行的内容,给header添加显示省略号的css代码,并且要把header的文字内容包含在el-tooltip里面
下面的是效果图:
文章来源地址https://www.toymoban.com/news/detail-776035.html
到了这里,关于【vue】Element ui 表格的header 标题文字过于太长 而需要显示省略号并用tooltip显示全部信息的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!