element-plus/docs/examples/tree-v2/custom-node.vue
msidolphin 2d2878eb53
feat(components): add virtual tree (#3398)
* feat(components): add virtual tree

* perf: optimize compute performance

* perf: optimize update checked states performance

* feat(components): [tree-v2] supports filter method

* feat(components): [el-tree-v2] exposes check api

* feat(components): [el-tree-v2] exposes current api

* feat(components): [el-tree-v2] support contextmenu event

* style(components): [el-tree-v2] optimized code style

* refactor(components): [el-tree-v2] using svg icon

* refactor(components): [el-tree-v2] replace all PropType with buildProp

replace all PropType with buildProp, support perfMode, expose setData

* refactor: improve prop

* docs: [el-tree-v2] improve documention

* refactor(components): [el-tree-v2] optimized code

Co-authored-by: Kevin <sxzz@sxzz.moe>
2021-09-27 11:12:50 +08:00

62 lines
1.3 KiB
Vue

<template>
<el-tree-v2 :data="data" :props="props" :height="208">
<template #default="{ node }">
<span class="prefix" :class="{ 'is-leaf': node.isLeaf }"
>[ElementPlus]</span
>
<span>{{ node.label }}</span>
</template>
</el-tree-v2>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
const getKey = (prefix, id) => {
return `${prefix}-${id}`
}
const createData = (
maxDeep,
maxChildren,
minNodesNumber,
deep = 1,
key = 'node'
) => {
let id = 0
return new Array(minNodesNumber).fill(deep).map(() => {
const childrenNumber =
deep === maxDeep ? 0 : Math.round(Math.random() * maxChildren)
const nodeKey = getKey(key, ++id)
return {
id: nodeKey,
label: nodeKey,
children: childrenNumber
? createData(maxDeep, maxChildren, childrenNumber, deep + 1, nodeKey)
: undefined,
}
})
}
export default defineComponent({
setup() {
return {
data: createData(4, 30, 40),
props: ref({
id: 'id',
label: 'label',
children: 'children',
}),
}
},
})
</script>
<style lang="scss" scoped>
.prefix {
color: var(--el-color-primary);
margin-right: 10px;
&.is-leaf {
color: var(--el-color-success);
}
}
</style>