elmentui 如何在table组件的标题上 添加tooltip
时间: 2024-04-12 09:27:06 浏览: 6
要在 ElementUI 的 Table 组件的标题上添加 tooltip,你可以使用 `slot-scope` 属性来自定义标题的内容。首先,你需要在标题上添加一个 `el-tooltip` 组件,并将 tooltip 的内容放在其中。然后,将 tooltip 组件放在标题的 `slot-scope` 内。
以下是一个示例代码:
```html
<template>
<el-table :data="tableData" style="width: 100%">
<el-table-column label="Name">
<template slot-scope="scope">
<el-tooltip :content="scope.row.name" placement="top">
<span>{{ scope.row.name }}</span>
</el-tooltip>
</template>
</el-table-column>
<!-- 其他列 -->
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: 'John Doe', age: 30 },
{ name: 'Jane Smith', age: 25 },
// 其他数据
]
};
}
};
</script>
```
在上面的示例中,我们在 Name 列的标题上添加了一个 tooltip。tooltip 的内容是每行的 name 属性。你可以根据你的需求自定义 tooltip 的样式和内容。