Files
element-plus/docs/examples/tree/custom-node-class.vue
jiaxiang 23ce3ff8f1 chore: fix type error of the tree customNodeClass demo (#18920)
chore: fix type error of the tree demo
2024-11-16 21:52:39 +08:00

96 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 Node from 'element-plus/es/components/tree/src/model/node'
import type { TreeNodeData } from 'element-plus/es/components/tree/src/tree.type'
interface Tree {
id: number
label: string
isPenultimate?: boolean
children?: Tree[]
}
const customNodeClass = ({ isPenultimate }: TreeNodeData, node: Node) =>
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 {
color: #626aef;
}
.el-tree .el-tree-node.is-penultimate > .el-tree-node__children {
display: flex;
flex-direction: row;
}
.is-penultimate > .el-tree-node__children > div {
width: 25%;
}
</style>