Guide
Installation#
# Vue3
npm i --save @he-tree/vue
# Vue2
npm i --save @he-tree/vue @vue/composition-api
CDN#
Import#
Vue3#
import { BaseTree, Draggable } from '@he-tree/vue'
import '@he-tree/vue/style/default.css'
Vue2#
import { BaseTree, Draggable } from '@he-tree/vue/vue2'
import '@he-tree/vue/style/default.css'
BaseTree
is the base tree component. Draggable
component extends BaseTree
.
Examples#
Example Projects#
Basic#
Fold and Checkbox#
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#
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'}
]
}
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#
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
Render as Table#
action | Text | Level |
---|---|---|
Projects | 1 | |
Frontend | 2 | |
Vue | 3 | |
Nuxt | 4 | |
React | 3 | |
Next | 4 | |
Angular | 3 | |
Backend | 2 | |
Photos | 1 | |
Videos | 1 | |
action | Text | Level |
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'
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.
Drag cross trees.
Drag copy: copy node when drag start.
Draggable table.