Skip to content

TTree / 树形控件

Tree displays hierarchical data with expand/collapse, checkbox selection, and accordion mode. / 树形控件展示层级数据,支持展开/折叠、复选框选择和手风琴模式。

Props / 属性

PropType / 类型Default / 默认值Description / 说明
dataTreeNode[][]Tree node data
nodeKeystring'id'Unique key field
childrenstring'children'Children field name
labelKeystring'label'Label field name
showCheckboxbooleanfalseShow checkboxes
checkMode'cascade' | 'independent''cascade'Check mode
accordionbooleanfalseAccordion expand mode
defaultExpandAllbooleanfalseExpand all by default
variant'default' | 'flush''default'Visual variant
indentnumber24Indent in pixels

Basic Usage / 基础用法

vue
<script setup lang="ts">
import { TTree } from '@gulcc/tabler-vue'

const data = [
  { id: 1, label: 'Node 1 / 节点一', children: [
    { id: 2, label: 'Node 1.1 / 节点一' },
    { id: 3, label: 'Node 1.2 / 节点二' },
  ]},
]
</script>

<template>
  <TTree :data="data" default-expand-all />
</template>

Tips / 避坑指南

  • nodeKey must uniquely identify each node — used for tracking expanded/checked keys
  • checkMode="cascade" propagates checked state to parent/child nodes
  • When accordion=true, only one parent node can be expanded at a time
  • Node data can have any additional fields — they are passed through to rendering