-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathReloadChildren.vue
72 lines (65 loc) · 1.4 KB
/
ReloadChildren.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<template>
<button @click="handleClearChildren">Clear node-1 children</button>
<button @click="handleSetChildren">Set node-1 children</button>
<button @click="handleUpdateChildren">Update node-1 children</button>
<div :style="{ height: '300px' }">
<VTree ref="tree" checkable selectable />
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import VTree from '@wsfe/vue-tree'
const tree = ref()
const children = Array.from({ length: 100000 }).map((_, i) => {
return {
title: `node-1-${i + 1}`,
id: `node-1-${i + 1}`,
}
})
const data = [
{
title: 'node-1',
id: 'node-1',
children,
},
{
title: 'node-2',
id: 'node-2',
children: [
{
title: 'node-2-1',
id: 'node-2-1',
},
],
},
]
onMounted(() => {
tree.value.setData(data)
})
const handleSetChildren = () => {
tree.value.updateNode('node-1', { children })
}
const handleClearChildren = () => {
tree.value.updateNode('node-1', { children: [] })
}
const handleUpdateChildren = () => {
tree.value.updateNode('node-1', {
children: children.map((child) => {
return {
...child,
title: `${child.title} ${Date.now()}`,
checked: true,
}
})
})
}
</script>
<style scoped>
button {
border: 1px solid lightgray;
border-radius: 8px;
padding-left: 10px;
padding-right: 10px;
margin-right: 20px;
}
</style>