File tree Expand file tree Collapse file tree 2 files changed +118
-2
lines changed Expand file tree Collapse file tree 2 files changed +118
-2
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div class =" row" >
3
+ <div class =" col-2" >
4
+ <div class =" form-group" >
5
+ <div
6
+ class =" btn-group-vertical buttons"
7
+ role =" group"
8
+ aria-label =" Basic example"
9
+ >
10
+ <button
11
+ class =" btn btn-secondary"
12
+ @click =" add"
13
+ >Add</button >
14
+ <button
15
+ class =" btn btn-secondary"
16
+ @click =" remove"
17
+ >Remove</button >
18
+ <button
19
+ class =" btn btn-secondary"
20
+ @click =" clear"
21
+ >Clear</button >
22
+ </div >
23
+ </div >
24
+ </div >
25
+
26
+ <div class =" col-6" >
27
+ <h3 >Draggable</h3 >
28
+
29
+ <draggable
30
+ :list =" list"
31
+ :disabled =" !enabled"
32
+ class =" list-group"
33
+ ghost-class =" ghost"
34
+ >
35
+ <div
36
+ class =" list-group-item"
37
+ v-for =" element in list"
38
+ :key =" element.name"
39
+ >
40
+ {{ element.name }}
41
+ </div >
42
+
43
+ <template v-slot :header >
44
+ <div >
45
+ header slot
46
+ </div >
47
+ </template >
48
+
49
+ <template v-slot :footer >
50
+ <div >
51
+ footer slot
52
+ </div >
53
+ </template >
54
+ </draggable >
55
+ </div >
56
+
57
+ <rawDisplayer
58
+ class =" col-3"
59
+ :value =" list"
60
+ title =" List"
61
+ />
62
+ </div >
63
+ </template >
64
+
65
+ <script >
66
+ import draggable from " @/vuedraggable" ;
67
+
68
+ let id = 1 ;
69
+ export default {
70
+ name: " slot-example" ,
71
+ display: " Slot example" ,
72
+ order: 1 ,
73
+ debug: true ,
74
+ components: {
75
+ draggable
76
+ },
77
+ data () {
78
+ return {
79
+ enabled: true ,
80
+ list: [
81
+ { name: " John" , id: 0 },
82
+ { name: " Joao" , id: 1 },
83
+ { name: " Jean" , id: 2 }
84
+ ]
85
+ };
86
+ },
87
+ methods: {
88
+ clear : function () {
89
+ this .list = [];
90
+ },
91
+ add : function () {
92
+ this .list .push ({ name: " Juan " + id, id: id++ });
93
+ },
94
+ remove : function () {
95
+ this .list .pop ();
96
+ }
97
+ }
98
+ };
99
+ </script >
100
+ <style scoped>
101
+ .buttons {
102
+ margin-top : 35px ;
103
+ }
104
+
105
+ .ghost {
106
+ opacity : 0.5 ;
107
+ background : #c8ebfb ;
108
+ }
109
+ </style >
Original file line number Diff line number Diff line change @@ -55,13 +55,19 @@ function isTransition(slots) {
55
55
return isTransitionName ( componentOptions . tag ) ;
56
56
}
57
57
58
- function computeChildrenAndOffsets ( children , { header, footer } ) {
58
+ function getSlot ( slot , scopedSlot , key ) {
59
+ return slot [ key ] || ( scopedSlot [ key ] ? scopedSlot [ key ] ( ) : undefined ) ;
60
+ }
61
+
62
+ function computeChildrenAndOffsets ( children , slot , scopedSlot ) {
59
63
let headerOffset = 0 ;
60
64
let footerOffset = 0 ;
65
+ const header = getSlot ( slot , scopedSlot , "header" ) ;
61
66
if ( header ) {
62
67
headerOffset = header . length ;
63
68
children = children ? [ ...header , ...children ] : [ ...header ] ;
64
69
}
70
+ const footer = getSlot ( slot , scopedSlot , "footer" ) ;
65
71
if ( footer ) {
66
72
footerOffset = footer . length ;
67
73
children = children ? [ ...children , ...footer ] : [ ...footer ] ;
@@ -159,7 +165,8 @@ const draggableComponent = {
159
165
this . transitionMode = isTransition ( slots ) ;
160
166
const { children, headerOffset, footerOffset } = computeChildrenAndOffsets (
161
167
slots ,
162
- this . $slots
168
+ this . $slots ,
169
+ this . $scopedSlots
163
170
) ;
164
171
this . headerOffset = headerOffset ;
165
172
this . footerOffset = footerOffset ;
You can’t perform that action at this time.
0 commit comments