Skip to content

Commit 338bae3

Browse files
authored
Add vuex subsection to README
1 parent 6b850c1 commit 338bae3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ You can listen to Sortable events by adding the listeners to the `Sortable` comp
7575
>
7676
```
7777

78+
### Vuex
79+
No changes are necessary to work with Vuex. Just pass `store.state.item` as your list. To modify your data you need to manually listen to the events and calculate the new position with `event.oldIndex` and `event.newIndex` with something like the following:
80+
81+
```typescript
82+
const moveItemInArray = <T>(array: T[], from: number, to: number) => {
83+
const item = array.splice(from, 1)[0];
84+
array.splice(to, 0, item);
85+
};
86+
87+
onEnd(event) { moveItemInArray(store.state.items, event.oldIndex, event.newIndex }
88+
```
7889
## Development
7990
1. Run `yarn` to install dependencies
8091
2. `yarn dev` will start a web server with live reloading

0 commit comments

Comments
 (0)