100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > element-ui table列表自定义表头 修改列标题样式 添加tooltip

element-ui table列表自定义表头 修改列标题样式 添加tooltip

时间:2024-07-16 22:56:34

相关推荐

element-ui table列表自定义表头 修改列标题样式 添加tooltip

亲测可用,若有疑问请私信

在之前的博客中,提到在element-ui table列表自定义表头,修改列标题样式、添加tooltip,需要render-header,但是在2.4.11及以后,element-ui官方已经更新了,并添加了自定义表头的方法

为了广大的群众少走弯路,我觉得还是有必要更新一下,如果element-ui版本是2.4.11以下,可以参考上个关于自定义表头的博客Element-ui自定义table表头,修改列标题样式、添加tooltip, :render-header使用简介

如果是2.4.11及以上版本就可以参考本文啦~

通过设置 Scoped slot 来自定义表头。

官方文档中描述通过设置 Scoped slot 来自定义表头,使用了vue中slot插槽的方法。

如果还不清楚slot是什么,怎么用可以先参考一下vue官网文档 vue插槽

用法示例:

<template slot="header" slot-scope="scope">

...

</template>

这个用法还是很人性化也比较简单的,看看element-ui官方的文档完全可以掌握,但是本着负责任的态度,还是写一下

在这拿在表头添加一个tooltip作为示范,在名字的后面加个tooltip提示信息

<template>

<el-table

:data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"

style="width: 100%">

<el-table-column

label="Date"

prop="date">

</el-table-column>

<el-table-column

prop="name">

<template slot="header" slot-scope="scope">

<span>名字</span>

<el-tooltip class="item" effect="dark" content="Right Center 提示文字" placement="right">

<i class="el-icon-question"></i>

</el-tooltip>

</template>

</el-table-column>

<el-table-column

align="right">

<template slot="header" slot-scope="scope">

<el-input

v-model="search"

size="mini"

placeholder="输入关键字搜索"/>

</template>

<template slot-scope="scope">

<el-button

size="mini"

@click="handleEdit(scope.$index, scope.row)">Edit</el-button>

<el-button

size="mini"

type="danger"

@click="handleDelete(scope.$index, scope.row)">Delete</el-button>

</template>

</el-table-column>

</el-table>

</template>

<script>

export default {

data() {

return {

tableData: [{

date: '-05-02',

name: '王小虎',

address: '上海市普陀区金沙江路 1518 弄'

}, {

date: '-05-04',

name: '王小虎',

address: '上海市普陀区金沙江路 1517 弄'

}, {

date: '-05-01',

name: '王小虎',

address: '上海市普陀区金沙江路 1519 弄'

}, {

date: '-05-03',

name: '王小虎',

address: '上海市普陀区金沙江路 1516 弄'

}],

search: ''

}

},

methods: {

handleEdit(index, row) {

console.log(index, row);

},

handleDelete(index, row) {

console.log(index, row);

}

},

}

</script>

代码都是Element-ui官方文档里的,仅作为参考使用,知道怎么用就可以了

效果如下:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。