Skip to content

Tree

Basic usage

Almost anything can be represented in a tree structure. Examples include directories, organization hierarchies, biological classifications, countries, etc. The Tree component is a way of representing the hierarchical relationship between these things. You can also expand, collapse, and select a treeNode within a Tree.

Customize Icon

You can customize icons for different nodes.

load data asynchronously

To load data asynchronously when click to expand a treeNode.

Tree With Line

Customize collapse/expand icon

ReplaceFields

Replace the title,key and children fields in treeNode with the corresponding fields in treeData.

Virtual scroll

Use virtual list through height prop.

查询树节点

Use the setExpand method to expand the corresponding parent node, and use the scrollTo method to scroll to the specified node.

API

Tree Attributes

NameDescriptionTypeDefaultVersion
blockNodeWhether treeNode fill remaining horizontal spacebooleanfalse
checkableAdds a Checkbox before the treeNodesbooleanfalse
checkedKeys(v-model)Specifies the keys of the checked treeNodesstring[] | number[][]
defaultExpandAllWhether to expand all treeNodes by defaultbooleanfalse
disabledwhether disabled the treebooleanfalse
expandedKeys(v-model)Specifies the keys of the expanded treeNodesstring[] | number[][]
fieldNamesReplace the label,value and children fields in treeNode with the corresponding fields in treeDataobject{children:'children', label:'label', value:'value' }
heightConfig virtual scroll height. Will not support horizontal scroll when enable thisnumber
loadLoad data asynchronouslyfunction(node)
multipleAllows selecting multiple treeNodesbooleanfalse
selectablewhether can be selectedbooleantrue
selectedKeys(v-model)Specifies the keys of the selected treeNodesstring[] | number[][]
showIconShows the icon before a TreeNode's title.booleanfalse
showLineShows a connecting linebooleanfalse
treeDatatreeNode of treeTreeNode[]

Tree Events

NameDescriptionType
selectCallback function for when the user clicks a treeNode(checkedKeys: (string | number)[], e: { node: any }) => void
expandCallback function for when a treeNode is expanded or collapsed(expandedKeys: (string | number)[], e: { expand: boolean; node: any }) => void
checkCallback function for when the onCheck event occurs(checkedKeys: (string | number)[], e: { checked: boolean; node: any }) => void

TreeNode

NameDescriptionTypeDefault
checkableWhen Tree is checkable, set TreeNode display Checkbox or notboolean
disableCheckboxDisables the checkbox of the treeNodebooleanfalse
disabledDisables the treeNodebooleanfalse
isLeafDetermines if this is a leaf node(effective when loadData is specified)booleanfalse
keyUsed with (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys.string | number
titleTitlestring

Tree Slots

NameDescription
iconcustomize icon
switcherIconcustomize collapse/expand icon of tree node
titlecustom title

Tree Exposes

NameDescriptionType
setExpandSet expandedKeys(str: string | ((node: TreeNodeType) => boolean)) => instance
scrollToScroll to the node(Enable virtual scroll and reach the desired quantity height / 28 Round Up)(key: string | number) => instance

Contributors

lazy

ChangeLog

8650f - fix: 修复异步数据层级不对问题 on 1/20/2025
d4601 - style: 修正tree样式 on 1/16/2025
07ae9 - feat: 增加查询的展开和滚动定位 on 1/9/2025
9dbd9 - fix: 修复tree默认全展开无法闭合 on 12/9/2024
99cf6 - feat: tree增加父节点展开 on 12/9/2024
d60f9 - style: 删除多余class on 4/23/2024
cd98c - feat: tree on 4/19/2024

Released under the MIT License.