Skip to content

Commit b75dd0b

Browse files
Update readme with v-for example
1 parent b330f58 commit b75dd0b

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

README.md

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,10 @@ Based on and offering all features of [Sortable.js](https://github.com/RubaXa/So
3636

3737
Use draggable component:
3838

39-
Typical use:
39+
### Typical use:
4040
``` html
41-
<draggable :list="list" :options="{group:'people'}" @start="drag=true" @end="drag=false">
42-
<div v-for="element in list">{{element.name}}</div>
43-
</draggable>
44-
```
45-
46-
With `transition-group`:
47-
``` html
48-
<draggable :list="list">
49-
<transition-group>
50-
<div v-for="element in list" :key="element.id">
51-
{{element.name}}
52-
</div>
53-
</transition-group>
41+
<draggable v-model="myArray" :options="{group:'people'}" @start="drag=true" @end="drag=false">
42+
<div v-for="element in myArray">{{element.name}}</div>
5443
</draggable>
5544
```
5645
.vue file:
@@ -64,16 +53,61 @@ With `transition-group`:
6453
...
6554
```
6655
56+
### With `transition-group`:
57+
``` html
58+
<draggable v-model="myArray">
59+
<transition-group>
60+
<div v-for="element in myArray" :key="element.id">
61+
{{element.name}}
62+
</div>
63+
</transition-group>
64+
</draggable>
65+
```
66+
67+
6768
Draggable component should directly wrap the draggable elements, or a `transition-component` containing the draggable elements.
6869
70+
71+
### With Vuex:
72+
73+
```html
74+
<draggable v-model='myList'>
75+
```
76+
77+
```javascript
78+
computed: {
79+
myList: {
80+
get() {
81+
return this.$store.state.myList
82+
},
83+
set(value) {
84+
this.$store.commit('updateList', value)
85+
}
86+
}
87+
}
88+
```
89+
90+
6991
### Props
92+
#### value
93+
Type: `Array`<br>
94+
Required: `false`<br>
95+
Default: `null`
96+
97+
Input array to draggable component. Typically same array as referenced by inner element v-for directive.<br>
98+
Should not used directly but used only though the `v-model` directive:
99+
```html
100+
<draggable v-model="myArray">
101+
```
102+
70103
#### list
71104
Type: `Array`<br>
72105
Required: `false`<br>
73106
Default: `null`
74107
75-
Array to be synchronized with drag-and-drop. Typically same array as referenced by inner element v-for directive.<br>
76-
When using children elements not linked to a "v-for" directive, use null.
108+
Altenative to the `value` prop, list is an array to be synchronized with drag-and-drop.<br>
109+
The main diference is that `list` prop is updated by draggable component using splice method, whereas `value` is immutable.<br>
110+
Using `v-model` and `value` is the compatible with Vuex and thus is the preferred way of using draggable.
77111
78112
#### options
79113
Type: `Object`<br>

0 commit comments

Comments
 (0)