You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Draggable component should directly wrap the draggable elements, or a `transition-component` containing the draggable elements.
109
-
110
-
111
104
### With footer slot:
112
105
``` html
113
-
<draggable v-model="myArray"draggable=".item">
114
-
<div v-for="element in myArray":key="element.id"class="item">
115
-
{{element.name}}
116
-
</div>
117
-
<template slot="footer">
118
-
<button @click="addPeople">Add</button>
119
-
</template>
106
+
<draggable v-model="myArray"item-key="id">
107
+
<template #item="{element}">
108
+
<div>{{element.name}}</div>
109
+
</template>
110
+
<template #footer>
111
+
<button @click="addPeople">Add</button>
112
+
</template>
120
113
</draggable>
121
114
```
122
115
### With header slot:
123
116
``` html
124
-
<draggable v-model="myArray"draggable=".item">
125
-
<div v-for="element in myArray":key="element.id"class="item">
126
-
{{element.name}}
127
-
</div>
128
-
<template slot="header">
129
-
<button @click="addPeople">Add</button>
130
-
</template>
117
+
<draggable v-model="myArray"item-key="id">
118
+
<template #item="{element}">
119
+
<div>{{element.name}}</div>
120
+
</template>
121
+
<template #header>
122
+
<button @click="addPeople">Add</button>
123
+
</template>
131
124
</draggable>
132
125
```
133
126
@@ -174,8 +167,6 @@ The main difference is that `list` prop is updated by draggable component using
174
167
**Do not use in conjunction with modelValue prop.**
175
168
176
169
#### All sortable options
177
-
New in version 2.19
178
-
179
170
Sortable options can be set directly as vue.draggable props since version 2.19.
180
171
181
172
This means that all [sortable option](https://github.com/RubaXa/Sortable#options) are valid sortable props with the notable exception of all the method starting by "on" as draggable component expose the same API via events.
@@ -259,10 +250,12 @@ Value: an object corresponding to the attributes, props and events we would pass
259
250
260
251
Example (using [element UI library](http://element.eleme.io/#/en-US)):
@@ -320,60 +313,37 @@ Limitation: neither header or footer slot works in conjunction with transition-g
320
313
321
314
#### Header
322
315
Use the `header` slot to add none-draggable element inside the vuedraggable component.
323
-
Important: it should be used in conjunction with draggable option to tag draggable element.
324
-
Note that header slot will always be added before the default slot regardless its position in the template.
325
316
Ex:
326
317
327
318
``` html
328
-
<draggable v-model="myArray"draggable=".item">
329
-
<div v-for="element in myArray":key="element.id"class="item">
330
-
{{element.name}}
331
-
</div>
332
-
<template slot="header">
333
-
<button @click="addPeople">Add</button>
334
-
</template>
319
+
<draggable v-model="myArray"item-key="id">
320
+
<template #item="{element}">
321
+
<div>{{element.name}}</div>
322
+
</template>
323
+
<template #header>
324
+
<button @click="addPeople">Add</button>
325
+
</template>
335
326
</draggable>
336
327
```
337
328
338
329
#### Footer
339
330
Use the `footer` slot to add none-draggable element inside the vuedraggable component.
340
-
Important: it should be used in conjunction with draggable option to tag draggable elements.
341
-
Note that footer slot will always be added after the default slot regardless its position in the template.
342
331
Ex:
343
332
344
333
``` html
345
-
<draggable v-model="myArray"draggable=".item">
346
-
<div v-for="element in myArray":key="element.id"class="item">
347
-
{{element.name}}
348
-
</div>
349
-
<template slot="footer">
350
-
<button @click="addPeople">Add</button>
351
-
</template>
334
+
<draggable v-model="myArray"item-key="id">
335
+
<template #item="{element}">
336
+
<div>{{element.name}}</div>
337
+
</template>
338
+
<template #footer>
339
+
<button @click="addPeople">Add</button>
340
+
</template>
352
341
</draggable>
353
342
```
354
-
### Gotchas
355
-
356
-
- Vue.draggable children should always map the list or modelValue prop using a v-for directive
357
-
* You may use [header](https://github.com/SortableJS/Vue.Draggable#header) and [footer](https://github.com/SortableJS/Vue.Draggable#footer) slot to by-pass this limitation.
358
-
359
-
- Children elements inside v-for should be keyed as any element in Vue.js. Be careful to provide relevant key values in particular:
360
-
* typically providing array index as keys won't work as key should be linked to the items content
361
-
* cloned elements should provide updated keys, it is doable using the [clone props](#clone) for example
0 commit comments