Skip to content

API reference ​

These four tables mirror lib/VueGiantTree.vue's defineProps / defineExpose / slots and defineEmits; defaults come from withDefaults.

Props ​

propTypeDefaultDescription
modelValueTreeNodeData | TreeNodeData[] | string | string[]—The selection (v-model)
treeTreeInputItem[][]Tree data in adjacency-list form
rootstring''Root identifier; top-level nodes' parentId must equal it
widthstring'100%'Container width
heightstring'100%'Container height
lineHeightnumber26Row height in pixels
fontSizestring'14px'Font size
selectTypeSelectTypeSelectType.CHECKBOXCHECKBOX / RADIO / SELECT
fieldKeysTreeFieldKeys{}Field-name mapping for the input JSON
outputIdOnlybooleantruetrue gives IDs in v-model; false gives full nodes
checkedOutputModeCheckedOutputModeCheckedOutputMode.AllOutput filter mode for CHECKBOX
filterFnFilterFn—Custom filter (filters output in CHECKBOX+Custom; filters selectability in RADIO)
nodeIconboolean | NodeIconResolverfalseNode icons: true for built-ins, or a per-node callback
showLineboolean | ShowLineOptionsfalseGuide-line mode
chunkedBuildbooleanfalseWrite WASM input in batches
buildBatchSizenumber2000Nodes per batch
workerModebooleanfalseRun tree algorithms in a Web Worker
preorderedInputbooleanfalseSkip generic grouping when input is already depth-first preorder

Methods ​

Call them through a component ref.

MethodDescription
expandAll()Expands every expandable node in the current view
collapseAll()Collapses every expandable node in the current view
fuzzySearch(keyword)Debounced (300ms) fuzzy search; an empty string clears it
fuzzySearchRaw(keyword)Immediate fuzzy search; an empty string clears it
switchDisplay(displayType)Switches between the TREE and SEARCH views
getTreeSize()Total node count
getBuildReady()Whether the initial build has completed
getBuildMetrics()Per-phase timings of the latest build
getWorkerMetrics()Worker queue, round-trip, serialization and structural-batch metrics
setChecked(id)Sets a single checked node
setCheckedByIds(ids)Sets checked nodes in bulk
clearAllChecked()Clears all checked state
refreshCheckedResult()Re-emits the current v-model result using the active output settings
updateNode(id, patch)Updates raw node fields; the ID cannot be changed
addNode(node)Adds a node under root or an existing parent
removeNode(id)Removes a node and its entire subtree

Slots ​

Both slots receive { node } — the current row's TreeNodeData.

SlotDescription
#nodeReplaces the node-content area; defaults to node.name
#actionsEnd-of-row actions area; omitted when unused, and its clicks never select the row

#actions does not mutate data on its own. The consuming application can use the instance APIs below with v-model:tree when an action should change data.

vue
<VueGiantTree :tree="treeData" root="root" v-model="selected">
  <template #actions="{ node }">
    <button @click="edit(node)">Edit</button>
    <button @click="remove(node)">Delete</button>
  </template>
</VueGiantTree>

Events ​

EventPayloadDescription
update:modelValueTreeNodeData | TreeNodeData[] | string | string[]The selection changed
update:treeTreeInputItem[]The new input array after an edit
item-contextmenu(node: TreeNodeData, event: MouseEvent)Right-click on a row; the component does not call preventDefault() for you

The component only emits an event; it ships no menu UI. Right-clicking a row emits item-contextmenu(node, event), where node is the row's TreeNodeData and event is the native MouseEvent. The component does not call preventDefault(), so the browser's native menu still opens — call event.preventDefault() in your handler to replace it. Rendering, positioning and closing the menu are the consumer's responsibility; a common approach is Teleport to body positioned with event.clientX/clientY. Right-click never triggers row click/selection.

vue
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeNodeData } from 'vue3-giant-tree-wasm'

const menu = ref<{ x: number; y: number; node: TreeNodeData } | null>(null)

const onContextMenu = (node: TreeNodeData, event: MouseEvent) => {
  event.preventDefault()
  menu.value = { x: event.clientX, y: event.clientY, node }
}
</script>

<template>
  <VueGiantTree :tree="treeData" root="root" v-model="selected" @item-contextmenu="onContextMenu" />

  <Teleport to="body">
    <ul v-if="menu" class="my-menu" :style="{ left: menu.x + 'px', top: menu.y + 'px' }">
      <li @click="edit(menu.node)">Edit</li>
      <li @click="remove(menu.node)">Delete</li>
    </ul>
  </Teleport>
</template>

Try it ​

Every capability above can be switched live in the full playground.