Commit 9298b3c988c10b81d83430ca31b9ce1d98a3fad9
1 parent
8d22231a
feat: add Tree LoadData demo
Showing
1 changed file
with
32 additions
and
2 deletions
src/views/demo/tree/index.vue
... | ... | @@ -26,10 +26,13 @@ |
26 | 26 | class="w-1/3" |
27 | 27 | /> |
28 | 28 | </div> |
29 | + <div class="flex"> | |
30 | + <BasicTree title="异步树" :treeData="tree" class="w-1/3" :load-data="onLoadData" /> | |
31 | + </div> | |
29 | 32 | </PageWrapper> |
30 | 33 | </template> |
31 | 34 | <script lang="ts"> |
32 | - import { defineComponent } from 'vue'; | |
35 | + import { defineComponent, ref } from 'vue'; | |
33 | 36 | import { BasicTree } from '/@/components/Tree/index'; |
34 | 37 | import { treeData } from './data'; |
35 | 38 | import { PageWrapper } from '/@/components/Page'; |
... | ... | @@ -40,7 +43,34 @@ |
40 | 43 | function handleCheck(checkedKeys, e) { |
41 | 44 | console.log('onChecked', checkedKeys, e); |
42 | 45 | } |
43 | - return { treeData, handleCheck }; | |
46 | + const tree = ref([ | |
47 | + { | |
48 | + title: 'parent ', | |
49 | + key: '0-0', | |
50 | + }, | |
51 | + ]); | |
52 | + | |
53 | + function onLoadData(treeNode) { | |
54 | + return new Promise((resolve: (value?: unknown) => void) => { | |
55 | + if (!treeNode.children) { | |
56 | + resolve(); | |
57 | + return; | |
58 | + } | |
59 | + setTimeout(() => { | |
60 | + tree.value.forEach((v) => { | |
61 | + if (v.key === treeNode.eventKey) { | |
62 | + v.children = [ | |
63 | + { title: 'Child Node', key: `${treeNode.eventKey}-0` }, | |
64 | + { title: 'Child Node', key: `${treeNode.eventKey}-1` }, | |
65 | + ]; | |
66 | + } | |
67 | + }); | |
68 | + resolve(); | |
69 | + return; | |
70 | + }, 1000); | |
71 | + }); | |
72 | + } | |
73 | + return { treeData, handleCheck, tree, onLoadData }; | |
44 | 74 | }, |
45 | 75 | }); |
46 | 76 | </script> | ... | ... |