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.
Block node
The treeNode occupy the remaining horizontal space.
Multiple Select
By setting multiple, the tree can support multiple selection.
Checkable
Setting the checkable attribute to display the checkbox, and you can use defaultCheckedKeys to specify which nodes are checked by default.
Checkable
Check strictly
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.
Dynamic loading
Load nodes dynamically.
Draggable
Draggable nodes.
Checked strategy
Setting checkedStrategy attribute to set the return value when selected.
Current: []
Show line
Setting the showLine attribute to display the connecting line.
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.
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.
Extra node
Tree provides Slot named extra, which can customize extra content on the node.
Virtual list
Setting the virtualListProps attribute to display virtual list
Searchable
Show how to achieve the search tree effect.
Customize data
You can customize data by fieldNames.
Size
Trees of different sizes.
Tree API
Tree Attributes
Name | Description | Type | Default |
---|---|---|---|
size | Size | String | medium |
block-node | Whether the node occupies a row | Boolean | false |
default-expand-all | Whether to expand the parent node by default | Boolean | true |
multiple | Whether to support multiple selection | Boolean | false |
checkable | Whether to add a checkbox before the node | Boolean | false |
selectable | Whether to support selection | Boolean | true |
check-strictly | Whether to cancel the parent-child node association | Boolean | false |
checked-strategy | Customized 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 | String | all |
default-selected-keys | Tree node selected by default | Array | - |
selected-keys / v-model | Selected tree node | Array | - |
default-checked-keys | Tree node with checkbox selected by default | Array | - |
checked-keys / v-model | Tree node with check box selected | Array | - |
default-expanded-keys | Nodes expanded by default | Array | - |
expanded-keys / v-model | Expanded node | Array | - |
data | Pass in data to generate the corresponding tree structure | Array | [] |
field-names | Specify the field name in the node data | Object | - |
show-line | Whether to display the connection line | Boolean | false |
load-more | A callback for loading data asynchronously, returning a Promise | Function | - |
draggable | Whether it can be dragged | Boolean | false |
allow-drop | Whether to allow release on a node when dragging | Function | - |
virtual-list-props | Pass virtual list properties, pass in this parameter to turn on virtual scrolling, VirtualListProps | Object | - |
default-expand-selected | Whether to expand the parent node of the selected node by default | Boolean | false |
default-expand-checked | Whether to expand the parent node of the checked node by default | Boolean | false |
auto-expand-parent | Whether to automatically expand the parent node of the expanded node | Boolean | true |
half-checked-keys / v-model | The keys of half checked. Only valid when checkable and checkStrictly | Array | - |
only-check-leaf | When 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) | Boolean | false |
animation | Whether to enable expand transition animation | Boolean | true |
action-on-node-click | The action triggered when the node is clicked | String | - |
Tree Events
Name | Description | Type |
---|---|---|
select | Triggered when the tree node is clicked | Function |
check | Triggered when the tree node checkbox is clicked. | Function |
expand | expand/close | Function |
drag-start | Node starts dragging | - |
drag-end | Node end drag | Function |
drag-over | The node is dragged to the releasable target | Function |
drag-leave | Node leaves to release the target | Function |
drop | The node is released on a releasable target | Function |
Tree Methods
Name | Description | Type | Return |
---|---|---|---|
scrollIntoView | Virtual list scroll to an element | Function | - |
getSelectedNodes | Get selected nodes | - | TreeNodeData[] |
getCheckedNodes | Get checked nodes. Supports passing in checkedStrategy, if not passed, the configuration of the component is taken. | Function | TreeNodeData[] |
getHalfCheckedNodes | Get half checked nodes | - | TreeNodeData[] |
getExpandedNodes | Get expanded nodes | - | TreeNodeData[] |
checkAll | Set the checkbox state of all nodes | Function | - |
checkNode | Sets the checkbox state of the specified node | Function | - |
selectAll | Set the selected state of all nodes | Function | - |
selectNode | Sets the selected state of the specified node | Function | - |
expandAll | Set the expanded state of all nodes | Function | - |
expandNode | Sets the expanded state of the specified node | Function | - |
Tree Slots
Name | Description | Params |
---|---|---|
title | Title | - |
extra | Render additional node content | - |
drag-icon | Custom drag icon | node |
loading-icon | Custom loading icon | - |
switcher-icon | Custom switcher icon | - |
icon | Custom node icon | node |
TreeNodeData
Name | Description | Type | Return |
---|---|---|---|
key | Unique key | String Number | - |
title | The title of the node | String | - |
selectable | Whether to allow selection | Boolean | false |
disabled | Whether to disable the node | Boolean | false |
disableCheckbox | Whether to disable the checkbox | Boolean | false |
checkable | Whether to show checkbox | Boolean | false |
draggable | Whether it can be dragged | Boolean | false |
isLeaf | Whether it is a leaf node. Effective when loading dynamically | Boolean | false |
icon | Node icon | Function | - |
switcherIcon | Custom switcher icon, priority is greater than tree | Function | - |
loadingIcon | Customize loading icon, priority is greater than tree | Function | - |
dragIcon | Custom drag icon, priority is greater than tree | Function | - |
children | Child node | Array | - |
TreeFieldNames
Name | Description | Type | Return |
---|---|---|---|
key | Specify the field name of key in TreeNodeData | String | key |
title | Specify the field name of title in TreeNodeData | String | title |
disabled | Specify the field name of disabled in TreeNodeData | String | disabled |
children | Specify the field name of children in TreeNodeData | String | children |
isLeaf | Specify the field name of isLeaf in TreeNodeData | String | isLeaf |
disableCheckbox | Specify the field name of disableCheckbox in TreeNodeData | String | disableCheckbox |
checkable | Specify the field name of checkable in TreeNodeData | String | checkable |
icon | Specify the field name of icon in TreeNodeData | String | checkable |
VirtualListProps
Name | Description | Type | Default |
---|---|---|---|
height | Viewable area height | Number String | - |
threshold | The 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 | - |
isStaticItemHeight | Is the element height fixed | Boolean | false |
fixedSize | Is the element height fixed. | Boolean | false |
estimatedSize | Is the element height fixed. | Number | - |
buffer | The number of elements mounted in advance outside the boundary of the viewport. | Number | 10 |