Skip to content

VTree API

VTree Props

PropDescriptionTypeDefault Value
valueSelected or checked value. Supports v-model. value will be a string or number in single select mode; a separator separated string or an array in multiple select mode. Multiple select mode takes the prioritystring | number | Array<string | number>None
dataTree data. It's recommended to use setData method instead of props when the data amount is largeobject[][]
unloadDataListThe list for querying node title of not loaded but selected nodes. The format is the same as dataobject[][]
showUnloadCheckedNodesWhether to show checked nodes that are not loaded after filterbooleantrue
emptyTextNo data textstring'暂无数据'
titleFieldNode title fieldstring'title'
keyFieldNode unique key fieldstring'id'
separatorSeparator of value in multiple select modestring','
checkableEnable multiple selectbooleanfalse
selectableEnable single selectbooleanfalse
filteredNodeCheckableWhether the filtered nodes can be checkedbooleanfalse
cascadeWhether parent nodes and child nodes are cascadedbooleantrue
enableLeafOnlyWhether to enable leaf nodes only. Effective when 'in multiple select mode and cascade is false' or 'in single select mode'booleanfalse
disableAllWhether to disable all nodesbooleanfalse
defaultExpandAllWhether to expand all nodes by defaultbooleanfalse
defaultExpandedKeys DeprecatedDefault expanded keysArray<string | number>[]
expandedKeys 2.2.0Expanded node keys. The component will react to the changes of this propArray<string | number>[]
draggableWhether nodes can be draggedbooleanfalse
droppableWhether nodes can be droppedbooleanfalse
beforeDropMethodThis method will be invoked before node drop. Return true to allow dropping. Return false to prevent from dropping(dragKey: string | number, dropKey: string | number, hoverPart: 'before' | 'body' | 'after') => boolean() => true
ignoreModeSpecify the nodes to ignore in getCheckedNodes, getCheckedKeys and v-model'none' | 'parents' | 'children''none'
autoLoadWhether to auto load root nodes when initbooleantrue
loadasync load method(node: null | TreeNode, resolve: Function, reject: Function) => anyNone
renderNode render function(h: CreateElement, node: TreeNode) => VNodeNone
filterMethodNode filter method(keyword: string, node: TreeNode) => booleanNone
expandOnFilter 2.1.0Whether to expand all visible nodes when filterbooleantrue
unselectOnClick 2.1.0Whether to cancel select when click on selected nodebooleantrue
loadingWhether to show loading iconbooleanfalse
nodeClassNameClass passed to the root element of the node. Pass a function to customize class for each nodestring | object | Array<string | object> | (node: TreeNode) => string | object | Array<string | object>None
showLine 4.0.0Whether to show connecting lines. Pass object to specify line width, color, type and polyline. The density of dash dashDensity 4.1.0 ranges from 1 to 10boolean | { width?: number, type?: 'dashed' | 'solid', color?: string, polyline?: boolean, dashDensity?: number }None. If not boolean, the default value is { width: 1, type: 'solid', color: '#D3D3D3', polyline: false, dashDensity: 3 }
animation 4.0.0Whether to enable transition animation. This prop only controls expand/collapse animation currentlybooleanNone
nodeMinHeightCalculate data total height according to node min heightnumber30
nodeIndentChild node indentnumber20
renderNodeAmountNode amount to render. Not all visible nodes will be rendered when they are more than this prop and the height is more than (node amount the container clientHeight can hold + bufferNodeAmount)number100
bufferNodeAmountRefresh render nodes when scrolled node amount is more than this propnumber20

VTree Events

Note: Since 2.0.8, the node info returned in events contains the full node info including _parent and children(dataTransfer in drag events excluded).

EventDescriptionReturn Value
inputTriggers when selected or checked nodes changesSelected or checked nodes
expandTriggers when expand/collapse nodeNode info
checkTriggers when check nodeChecked node info
uncheckTriggers when cancel check nodeCancel checked node info
checked-changeTriggers when checked nodes changesAll checked nodes (an array)
selectTriggers when select nodeSelected node info
unselectTriggers when cancel select nodeCancel selected node info
selected-changeTriggers when selected node changesSelected node
clickTriggers when click nodeNode info, mouse event
node-dblclickTriggers when double click nodeNode info, mouse event
node-right-clickTriggers when right click nodeNode info, mouse event
node-dragstartTriggers when start dragging nodeNode info, drag event
node-dragenterTriggers when dragenterNode info, drag event, node part that triggers event 'before' | 'body' | 'after'
node-dragoverTriggers when dragoverNode info, drag event, node part that triggers event 'before' | 'body' | 'after'
node-dragleaveTriggers when dragleaveNode info, drag event, node part that triggers event 'before' | 'body' | 'after'
node-dropTriggers when drop nodeNode info, drag event, node part that triggers event 'before' | 'body' | 'after'

VTree Methods

MethodDescriptionParamsReturn Value
setDataSet tree data to avoid large amount data being proxied by Vuedata: object[]: The same as data propvoid
setCheckedSet multiple select checked/not checkedkey: string | number: node key
value: boolean: is checked
void
setCheckedKeysBatch set multiple select checked/not checkedkeys: Array<string | number>: node key
value: boolean: is checked
void
checkAllCheck all nodesNonevoid
clearCheckedClear checked nodesNonevoid
setSelectedSet single select selected/not selectedkey: string | number: node key
value: boolean: is selected
void
setExpandSet node expand/collapsekey: string | number: node key
value: boolean: is expanded
expandParent: boolean = true: whether to expand parent nodes 2.0.6
void
setExpandKeysBatch set node expand/collapsekeys: Array<string | number>: node key
value: boolean: is expanded
void
setExpandAllSet expand/collapse allvalue: boolean: is expandedvoid
getCheckedNodesGet multiple select checked nodesignoreMode: 'none' | 'parents' | 'children': ignore part, default value is ignoreMode propTreeNode[]
getCheckedKeysGet multiple select checked node keysignoreMode: 'none' | 'parents' | 'children': ignore part, default value is ignoreMode propArray<string | number>
getIndeterminateNodesGet half checked nodesNoneTreeNode[]
getSelectedNodeGet single selected nodeNoneTreeNode | null
getSelectedKeyGet single selected node keyNoneTreeNode | null
getExpandNodesGet expanded nodesNoneTreeNode[]
getExpandKeysGet expanded node keysNoneTreeNode[]
getCurrentVisibleNodesGet current visible nodesNoneTreeNode[]
getNodeGet node by keykey: string | number: node keyTreeNode | null
getTreeDataGet tree format node dataNoneTreeNode[]
getFlatDataGet flattened tree dataNoneTreeNode[]
getNodesCountGet total node countNonenumber
insertBeforeInsert a node before reference nodeinsertedNode: node key or single node data
referenceKey: string | number: reference node key
TreeNode | null Returns inserted node
insertAfterInsert a node after reference nodeinsertedNode: node key or single node data
referenceKey: string | number: reference node key
TreeNode | null Returns inserted node
appendAppend a node to the first child layer of parent nodeinsertedNode: node key or single node data
parentKey: string | number: parent node key
TreeNode | null Returns inserted node
prependPrepend a node to the first child layer of parent nodeinsertedNode: node key or single node data
parentKey: string | number: parent node key
TreeNode | null Returns inserted node
removeRemove noderemovedKey: string | number: node key to removeTreeNode | null Returns removed node
filterFilter nodeskeyword: string: filter keyword
filterMethod: (keyword: string, node: TreeNode) => boolean: filter method, default to filterMethod prop. if filterMethod prop is not present, it's an internal method that searches node title
void
showCheckedNodesShow checked nodesshowUnloadCheckedNodes: boolean: whether to show checked nodes that are not loaded, default to prop valuevoid
loadRootNodesLoad root nodes from remoteNonePromise<void>
updateNode 4.1.0Update single nodekey: string | number: node key
newNode: object: new node data, some fields will be ignored, like those start with underscore '_', the key field and indeterminate, visible, isLeaf, etc.
void
updateNodes 4.1.0Update multiple nodesnewNodes: object[]: new nodes array, some specific fields will be ignored like updateNode, and the elements without key field also will be ignoredvoid
scrollToScroll to specific node positionkey: string | number: node key
verticalPosition: 'top' | 'center' | 'bottom' | number: vertical position of scrolling
void

VTree Slots

NameDescription
emptyNo data
loadingIcon displayed when loading
node 4.0.0Custom node, slotProps is { node: TreeNode }

VTree Data Fields

Note: It's better not to override the fields starting with '_' to avoid impact on the internal logic

FieldDescription
idDefault key field. You can specify other field as key by setting keyField prop
titleDefault display name. You can specify other field as title by setting titleField prop
checkedWhether node is checked in multiple select mode
selectedWhether node is selected in single select mode
indeterminateWhether node is half checked in multiple select mode
disabledWhether node is disabled
expandEffective to parent nodes. Whether node is expanded
visibleWhether node is visible
_filterVisibleWhether is visible after filter. If it's false, the node is not visible in other situations
_parentParent node
childrenChild node list
isLeafWhether is leaf node
_levelNode level, starting from 0
_loadingWhether is loading node
_loadedWhether node is loaded. Effective when async load