File tree Expand file tree Collapse file tree 4 files changed +55
-6
lines changed Expand file tree Collapse file tree 4 files changed +55
-6
lines changed Original file line number Diff line number Diff line change 186
186
</div >
187
187
</div >
188
188
189
+ <!-- 自定义节点 -->
190
+ <div class =" panel" >
191
+ <div class =" header" >自定义节点</div >
192
+ <div class =" body" >
193
+ <div class =" interface" >
194
+ <div style =" height : 300px " >
195
+ <VTree :data =" basicUsage" >
196
+ <template #node =" { node } " >
197
+ <button >{{ node.title }}</button >
198
+ </template >
199
+ </VTree >
200
+ </div >
201
+ </div >
202
+ <div class =" desc" >
203
+ <div class =" desc-block" >
204
+ 除了 render,也可以传入 slot 自定义树节点
205
+ <pre >
206
+ {{ nodeSlotDescText }}
207
+ </pre >
208
+ </div >
209
+ </div >
210
+ </div >
211
+ </div >
212
+
189
213
<!-- 远程 -->
190
214
<div class =" panel" >
191
215
<div class =" header" >远程</div >
@@ -418,6 +442,14 @@ export default defineComponent({
418
442
showLinePolyline .value = polyline
419
443
}
420
444
445
+ const nodeSlotDescText = `
446
+ <VTree :data="basicUsage">
447
+ <template #node="{ node }">
448
+ <button>{{ node.title }}</button>
449
+ </template>
450
+ </VTree>
451
+ `
452
+
421
453
return {
422
454
// 基本用法
423
455
basicUsage ,
@@ -454,6 +486,9 @@ export default defineComponent({
454
486
showLinePolyline ,
455
487
onShowLinePolylineBtnClick ,
456
488
489
+ // 自定义节点
490
+ nodeSlotDescText ,
491
+
457
492
// 远程
458
493
remoteShow ,
459
494
remoteLoad ,
Original file line number Diff line number Diff line change 25
25
@select =" handleNodeSelect"
26
26
@expand =" handleNodeExpand"
27
27
@node-drop =" handleNodeDrop"
28
- />
28
+ >
29
+ <template #default =" slotProps " >
30
+ <slot name =" node" v-bind =" slotProps" ></slot >
31
+ </template >
32
+ </VTreeNode >
29
33
<template v-if =" expandAnimation .ready .value " >
30
34
<Transition
31
35
name =" vtree-expand-animation"
54
58
@select =" handleNodeSelect"
55
59
@expand =" handleNodeExpand"
56
60
@node-drop =" handleNodeDrop"
57
- />
61
+ >
62
+ <template #default =" slotProps " >
63
+ <slot name =" node" v-bind =" slotProps" ></slot >
64
+ </template >
65
+ </VTreeNode >
58
66
</div >
59
67
</div >
60
68
</Transition >
73
81
@select =" handleNodeSelect"
74
82
@expand =" handleNodeExpand"
75
83
@node-drop =" handleNodeDrop"
76
- />
84
+ >
85
+ <template #default =" slotProps " >
86
+ <slot name =" node" v-bind =" slotProps" ></slot >
87
+ </template >
88
+ </VTreeNode >
77
89
</template >
78
90
<div :style =" { height: `${bottomSpaceHeight}px` }" ></div >
79
91
</div >
Original file line number Diff line number Diff line change 52
52
v-on =" dragListeners"
53
53
:draggable =" draggable && !disableAll && !data?.disabled"
54
54
>
55
- <component v-if =" renderFunction" :is =" renderComponent" ></component >
56
- <template v-else >{{ data ? data[titleField] : '' }}</template >
55
+ <slot :node =" data" >
56
+ <component v-if =" renderFunction" :is =" renderComponent" ></component >
57
+ <template v-else >{{ data ? data[titleField] : '' }}</template >
58
+ </slot >
57
59
</div >
58
60
</div >
59
61
<div :class =" dropAfterCls" ></div >
Original file line number Diff line number Diff line change 39
39
@set-data =" onSetData"
40
40
@checked-change =" checkedChange"
41
41
>
42
- <template v-for =" (_ , slot ) in $slots " : name = " slot " v-slot =" scope " >
42
+ <template v-for =" (_ , slot ) in $slots " v-slot :[ slot ] =" scope " >
43
43
<slot :name =" slot" v-bind =" scope" ></slot >
44
44
</template >
45
45
</VTree >
You can’t perform that action at this time.
0 commit comments