Guide

Installation#

# Vue3
npm i --save @he-tree/vue
# Vue2
npm i --save @he-tree/vue @vue/composition-api
sh

CDN#

Import#

Vue3#

import { BaseTree, Draggable } from '@he-tree/vue'
import '@he-tree/vue/style/default.css'
ts

Vue2#

import { BaseTree, Draggable } from '@he-tree/vue/vue2'
import '@he-tree/vue/style/default.css'
ts

BaseTree is the base tree component. Draggable component extends BaseTree.

Examples#

Example Projects#

Basic#

Projects
Frontend
Vue
Nuxt
React
Next
Angular
Backend
Photos
Videos

Fold and Checkbox#

Checked: []
Projects
Frontend
Vue
Nuxt
React
Next
Angular
Backend
Photos
Videos

Only function provided, you need add your own ui by slot. stat.checked has 3 value:true, false, null. null mean some child checked. Related methods: getChecked, getUnchecked, updateCheck, openAll, closeAll, isVisible.

Drag and Drop#

Projects
Frontend
Vue
Nuxt
React
Next
Angular
Backend
Photos
Videos

Indent#

Don't set node indent by css. Use prop indent.

Data#

Follow is example data. Key children can be modified by prop childrenKey, text can be modified by prop textKey.

{
  text: 'Root',
  children: [
    {text: 'Child'}
  ]
}
js

Data update by component#

v-model works. The component will clone data as inner data. When inner data changed, there are 3 ways to emit new data. It modifies binded data directly by default. Use prop updateBehavior to set the new data emit behavior. Available values of updateBehavior:

  • modify: modify binded data.
  • new: emit new data, suit for vuex.
  • disabled: don't do anything. You can use getData method to generate and get new data when you want.

Data update by user#

The component creates stat object for every node. It stores runtime info, such as open, parent, children, level. You can use prop statHandler handle each stat after they created. Related data: stats, statsFlat.

The methods to handle data: getStat, has, updateCheck, getChecked, getUnchecked, openAll, closeAll, isVisible, move, add, addMulti, remove, removeMulti, iterateParent, getSiblings, getData.

Virtual List#

Projects
Frontend
Vue
Nuxt
React
Next
Angular
Backend
Photos
Videos
Node-378
Node-609
Node-034
Node-706
Node-518
Node-716
Node-334
Node-288
Node-856
Node-614
Node-879
Node-668

Set height or max-height fot tree or its parent, or it will not work.Related props: virtualization, virtualizationPrerenderCount

Virtual list is implemented by another library of mine: virtual-list.

Open all nodes by default#

Related props: defaultOpen

Display from right to left#

Related props: rtl

Tree start from bottom to top#

Related props: btt

Angular
Next
React
Nuxt
Vue
Frontend
Projects

Render as Table#

actionTextLevel
Projects1
Frontend2
Vue3
Nuxt4
React3
Next4
Angular3
Backend2
Photos1
Videos1
actionTextLevel

Render as table and virtual list can work at the same time. Related props: table. Use slot prepend, append to add table head and foot. Draggable table is pro feature, get pro to enable it.

About Drag and Drop#

Drag Trigger Element#

Related props: triggerClass

Draggable and Droppable#

Use stat to control draggable and droppable for each node. Also can be controled by hooks. Related props: disableDrag, disableDrop, eachDraggable, eachDroppable, rootDroppable, maxLevel

Max Level#

Related props: maxLevel

Drag Open#

When drag over a node, it will be open by default. Use prop dragOpen to change it. Use prop dragOpenDelay to set delay time. Hook prop: beforeDragOpen

Placeholder#

It will use a light blue box to mark droppable position when drag. Use slot placeholder to customize it, such as add tips.

When drag leave tree, placeholder will be removed. Use prop keepPlaceholder to keep placeholder even leave tree.

Runtime info when drag#

In drag process, runtime info is in an exported object dragContext.

// vue3
import { dragContext } from '@he-tree/vue'
// vue2
import { dragContext } from '@he-tree/vue/vue2'
ts

Drop from outside#

When dropped from outside by Drag and Drop API, you can use hook props: onExternalDragOver, externalDataHandler to handle it. he-tree can work with any code which use HTML5 Drag and Drop API.

Touch & Mobile#

It is based on HTML5 Drag and Drop API. So it works in any device that supports Drag and Drop API. For others, you can try Drag and Drop API polyfill.

Watermark#

It prints a watermark information to browser console. Use prop watermark to disable it.

Pro#

pro has follow advanced features.