Files
element-plus/docs/examples/tree/custom-node-class.vue
bxh1071 48778958bb docs(components): [tree-v2] improve demo style (#23383)
* Add scoped styles for penultimate tree node

修正示例中的自定义类名样式未生效,节点颜色没变的问题。

* docs: update color

---------

Co-authored-by: rzzf <cszhjh@gmail.com>
2026-01-14 20:27:51 +08:00

99 lines
1.7 KiB
Vue

<template>
<div class="custom-tree-node-container">
<el-tree
style="max-width: 600px"
:data="data"
show-checkbox
node-key="id"
default-expand-all
:expand-on-click-node="false"
:props="{ class: customNodeClass }"
/>
</div>
</template>
<script lang="ts" setup>
import type { TreeNodeData } from 'element-plus'
interface Tree {
id: number
label: string
isPenultimate?: boolean
children?: Tree[]
}
const customNodeClass = ({ isPenultimate }: TreeNodeData) =>
isPenultimate ? 'is-penultimate' : ''
const data: Tree[] = [
{
id: 1,
label: 'Level one 1',
children: [
{
id: 4,
label: 'Level two 1-1',
isPenultimate: true,
children: [
{
id: 9,
label: 'Level three 1-1-1',
},
{
id: 10,
label: 'Level three 1-1-2',
},
],
},
],
},
{
id: 2,
label: 'Level one 2',
isPenultimate: true,
children: [
{
id: 5,
label: 'Level two 2-1',
},
{
id: 6,
label: 'Level two 2-2',
},
],
},
{
id: 3,
label: 'Level one 3',
isPenultimate: true,
children: [
{
id: 7,
label: 'Level two 3-1',
},
{
id: 8,
label: 'Level two 3-2',
},
],
},
]
</script>
<style>
.is-penultimate > .el-tree-node__content .el-tree-node__label {
color: #626aef;
}
.is-penultimate > .el-tree-node__children > div {
display: inline-block;
margin-right: 4px;
&:not(:first-child) .el-tree-node__content {
padding-left: 0px !important;
}
.el-tree-node__content {
padding-right: 16px;
}
}
</style>