Skip to content

Tree

Display a set of data with hierarchies.

Basic usage

Give each node a globally unique key (required), and the title is the content to be displayed on the node.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Block node

The treeNode occupy the remaining horizontal space.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Multiple Select

By setting multiple, the tree can support multiple selection.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Checkable

Setting the checkable attribute to display the checkbox, and you can use defaultCheckedKeys to specify which nodes are checked by default.

Checkable

Trunk 1
Leaf 1-1
Branch 1-2
Leaf 1-2-1
Leaf 1-2-2
Trunk 2
Branch 2-1
Leaf 2-1-1
Leaf 2-1-2
Leaf 2-2

Check strictly

Trunk 1
Leaf 1-1
Branch 1-2
Leaf 1-2-1
Leaf 1-2-2
Trunk 2
Branch 2-1
Leaf 2-1-1
Leaf 2-1-2
Leaf 2-2

V-model

The selectedKeys, checkedKeys, and expandedKeys attributes can all be controlled, not only supporting v-model, but also controlling how to update attribute values in the corresponding select / check / expand events.

Trunk 1
Leaf 1-1
Branch 1-2
Leaf 1-2-1
Trunk 2
Leaf 2-1
Leaf 2-2

Dynamic loading

Load nodes dynamically.

Trunk 1
Trunk 2
Branch 2-1

Draggable

Draggable nodes.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Checked strategy

Setting checkedStrategy attribute to set the return value when selected.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Current: []

Show line

Setting the showLine attribute to display the connecting line.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Leaf 1-1-2-1
Leaf 1-1-3
Branch 1-2
Branch 1-3
Leaf 1-3-1
Leaf 1-3-2
Trunk 2
Trunk 3
Branch 3-1
Leaf 3-1-1
Leaf 3-1-2

Node icon

The icon of a node can be specified globally via the icon slot of the tree, or individually via the icon property of the node.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Component icons

The node icons loadingIcon, switcherIcon, support customization at the two latitudes of tree and node at the same time, and node has a higher priority.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Extra node

Tree provides Slot named extra, which can customize extra content on the node.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Virtual list

Setting the virtualListProps attribute to display virtual list

1-1
1-1-1
1-1-1-1
1-1-1-2
1-1-1-3
1-1-1-4
1-1-1-5
1-1-1-6
1-1-1-7
1-1-1-8
1-1-1-9
1-1-1-10
1-1-2
1-1-2-1
1-1-2-2
1-1-2-3
1-1-2-4
1-1-2-5
1-1-2-6
1-1-2-7
1-1-2-8
1-1-2-9
1-1-2-10
1-1-3
1-1-3-1
1-1-3-2
1-1-3-3
1-1-3-4
1-1-3-5
1-1-3-6

Searchable

Show how to achieve the search tree effect.

Customize data

You can customize data by fieldNames.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Size

Trees of different sizes.

Trunk 1
Branch 1-1
Leaf 1-1-1
Leaf 1-1-2
Branch 1-2
Leaf 1-2-1

Tree API

Tree Attributes

NameDescriptionTypeDefault
sizeSizeStringmedium
block-nodeWhether the node occupies a rowBooleanfalse
default-expand-allWhether to expand the parent node by defaultBooleantrue
multipleWhether to support multiple selectionBooleanfalse
checkableWhether to add a checkbox before the nodeBooleanfalse
selectableWhether to support selectionBooleantrue
check-strictlyWhether to cancel the parent-child node associationBooleanfalse
checked-strategyCustomized backfill method
all: return all selected nodes
parent: return only parent node when both parent and child nodes are selected
child: return only child nodes
Stringall
default-selected-keysTree node selected by defaultArray-
selected-keys / v-modelSelected tree nodeArray-
default-checked-keysTree node with checkbox selected by defaultArray-
checked-keys / v-modelTree node with check box selectedArray-
default-expanded-keysNodes expanded by defaultArray-
expanded-keys / v-modelExpanded nodeArray-
dataPass in data to generate the corresponding tree structureArray[]
field-namesSpecify the field name in the node dataObject-
show-lineWhether to display the connection lineBooleanfalse
load-moreA callback for loading data asynchronously, returning a PromiseFunction-
draggableWhether it can be draggedBooleanfalse
allow-dropWhether to allow release on a node when draggingFunction-
virtual-list-propsPass virtual list properties, pass in this parameter to turn on virtual scrolling, VirtualListPropsObject-
default-expand-selectedWhether to expand the parent node of the selected node by defaultBooleanfalse
default-expand-checkedWhether to expand the parent node of the checked node by defaultBooleanfalse
auto-expand-parentWhether to automatically expand the parent node of the expanded nodeBooleantrue
half-checked-keys / v-modelThe keys of half checked. Only valid when checkable and checkStrictlyArray-
only-check-leafWhen enabled, checkedKeys is only for checked leaf nodes, and the status of the parent node is determined by the child node.(Only valid when checkable and checkStrictly is false)Booleanfalse
animationWhether to enable expand transition animationBooleantrue
action-on-node-clickThe action triggered when the node is clickedString-

Tree Events

NameDescriptionType
selectTriggered when the tree node is clickedFunction
checkTriggered when the tree node checkbox is clicked.Function
expandexpand/closeFunction
drag-startNode starts dragging-
drag-endNode end dragFunction
drag-overThe node is dragged to the releasable targetFunction
drag-leaveNode leaves to release the targetFunction
dropThe node is released on a releasable targetFunction

Tree Methods

NameDescriptionTypeReturn
scrollIntoViewVirtual list scroll to an elementFunction-
getSelectedNodesGet selected nodes-TreeNodeData[]
getCheckedNodesGet checked nodes. Supports passing in checkedStrategy, if not passed, the configuration of the component is taken.FunctionTreeNodeData[]
getHalfCheckedNodesGet half checked nodes-TreeNodeData[]
getExpandedNodesGet expanded nodes-TreeNodeData[]
checkAllSet the checkbox state of all nodesFunction-
checkNodeSets the checkbox state of the specified nodeFunction-
selectAllSet the selected state of all nodesFunction-
selectNodeSets the selected state of the specified nodeFunction-
expandAllSet the expanded state of all nodesFunction-
expandNodeSets the expanded state of the specified nodeFunction-

Tree Slots

NameDescriptionParams
titleTitle-
extraRender additional node content-
drag-iconCustom drag iconnode
loading-iconCustom loading icon-
switcher-iconCustom switcher icon-
iconCustom node iconnode

TreeNodeData

NameDescriptionTypeReturn
keyUnique keyStringNumber-
titleThe title of the nodeString-
selectableWhether to allow selectionBooleanfalse
disabledWhether to disable the nodeBooleanfalse
disableCheckboxWhether to disable the checkboxBooleanfalse
checkableWhether to show checkboxBooleanfalse
draggableWhether it can be draggedBooleanfalse
isLeafWhether it is a leaf node. Effective when loading dynamicallyBooleanfalse
iconNode iconFunction-
switcherIconCustom switcher icon, priority is greater than treeFunction-
loadingIconCustomize loading icon, priority is greater than treeFunction-
dragIconCustom drag icon, priority is greater than treeFunction-
childrenChild nodeArray-

TreeFieldNames

NameDescriptionTypeReturn
keySpecify the field name of key in TreeNodeDataStringkey
titleSpecify the field name of title in TreeNodeDataStringtitle
disabledSpecify the field name of disabled in TreeNodeDataStringdisabled
childrenSpecify the field name of children in TreeNodeDataStringchildren
isLeafSpecify the field name of isLeaf in TreeNodeDataStringisLeaf
disableCheckboxSpecify the field name of disableCheckbox in TreeNodeDataStringdisableCheckbox
checkableSpecify the field name of checkable in TreeNodeDataStringcheckable
iconSpecify the field name of icon in TreeNodeDataStringcheckable

VirtualListProps

NameDescriptionTypeDefault
heightViewable area heightNumberString-
thresholdThe threshold of the number of elements to enable virtual scrolling. When the number of data is less than the threshold, virtual scrolling will not be enabled.Number-
isStaticItemHeightIs the element height fixedBooleanfalse
fixedSizeIs the element height fixed.Booleanfalse
estimatedSizeIs the element height fixed.Number-
bufferThe number of elements mounted in advance outside the boundary of the viewport.Number10