Skip to content

t-tree-item

TreeItem 树形项

组件介绍

t-tree-item 是树形结构的子组件,用于递归渲染单个树节点及其子级,必须配合 t-tree 使用。支持展开折叠、复选框选择、懒加载、编辑删除等功能。

平台兼容

HarmonyH5AndroidiOS小程序UTS

基础用法

t-tree-item 作为 t-tree 的内部组件,通常不需要直接使用。t-tree 会自动递归渲染 t-tree-item

vue
<template>
  <t-tree :list="treeData" :show-checkbox="true">
  </t-tree>
</template>

<script setup>
const treeData = ref<UTSJSONObject[]>([
  {
    id: '1',
    label: '一级节点',
    children: [
      { id: '2', label: '二级节点 1' },
      { id: '3', label: '二级节点 2' }
    ]
  }
])
</script>

Props

属性名说明类型默认值
itemData当前节点的数据对象UTSJSONObject{}
sortIndex节点排序索引number0
selects选中的节点 ID 数组string[][]
folds折叠的节点 ID 数组string[][]
list树形数据列表UTSJSONObject[][]
accordion是否手风琴模式booleanfalse
load懒加载函数(node) => Promise<UTSJSONObject[]>-
showCheckbox是否显示复选框booleantrue
lazy是否开启懒加载booleanfalse
showAddButton是否显示添加按钮booleantrue
addIcon添加按钮图标string'plus-circle'
addIconClass添加按钮图标样式string''
showEditButton是否显示编辑按钮booleantrue
editIcon编辑按钮图标string'edit-pen'
editIconClass编辑按钮图标样式string''
showDeleteButton是否显示删除按钮booleantrue
deleteIcon删除按钮图标string'trash'
deleteIconClass删除按钮图标样式string''
rowHeight行高number50
idKey节点唯一标识字段名string'id'
labelKey节点标签字段名string'label'
disabledKey禁用状态字段名string'disabled'
childrenKey子节点字段名string'children'

Events

事件名说明回调参数
edit点击编辑按钮时触发(node: UTSJSONObject) => void
delete点击删除按钮时触发(node: UTSJSONObject) => void
add点击添加按钮时触发(node: UTSJSONObject) => void

数据结构

typescript
interface TreeNode {
  id: string
  label: string
  disabled?: boolean
  children?: TreeNode[]
}