@@ -29,29 +29,33 @@ import 'vue3-tree-vue/dist/style.css'; // remember to add this in your component
2929 setup () {
3030 const onItemChecked = (checkedItems : TreeViewItem []) => console .log (checkedItems );
3131 const onItemSelected = (item : TreeViewItem ) => console .log (item );
32- const onBeforeItemDropped = (droppedItem : TreeViewItem , dropHost : TreeViewItem | undefined ) => {
33- // dropHost == undefined means dropping at the root of the tree.
34-
35- // Here you can specify any kind of drop validation you will like.
36- // this function should return true if the drop operation is valid.
37-
38- if (dropHost .type !== playlist ) return false
39- return true ;
32+
33+
34+ // How to handle drag and drop logic
35+ const onBeforeItemDropped = (droppedItem : TreeViewItem , destinationNode : TreeViewItem | undefined ) => {
36+ // destinationNode == undefined means dropping at the root of the tree.
37+
38+ // Here you can specify any kind of drop validation you will like.
39+ // this function should return true if the drop operation is valid.
40+
41+ return new Promise ((resolve , _ ) => {
42+ resolve (droppedItem !== destinationNode ) // Replace this logic with your logic.
43+ });
4044 }
4145 const onItemExpanded = (expandedItem : TreeViewItem ) => {
42- // to use this feature properly you need to set lazyLoad property as true
43- // fetch data
44- const lazyLoadedItems = fetchFromApi (... );
45- expandedItem .children .push (... lazyLoadedItems )
46+ // to use this feature properly you need to set lazyLoad property as true
47+ // fetch data
48+ const lazyLoadedItems = fetchFromApi (... );
49+ expandedItem .children .push (... lazyLoadedItems )
4650 }
4751 const items = ref <TreeViewItem []>([]); // define your tree items here.
4852
4953 return {
50- onItemChecked ,
51- onItemSelected ,
52- onBeforeItemDropped ,
53- onItemExpanded ,
54- items
54+ onItemChecked ,
55+ onItemSelected ,
56+ onBeforeItemDropped ,
57+ onItemExpanded ,
58+ items
5559 }
5660 }
5761```
@@ -121,4 +125,4 @@ export interface TreeViewItem {
121125
122126| Name | Description |
123127| -------------|-------------
124- | on-item-hover | Use in ` child-append ` and ` item-append ` slots to only show when the cursor is hovering on the node
128+ | on-item-hover | Use in ` child-append ` and ` item-append ` slots to only show when the cursor is hovering on the node
0 commit comments