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
Copy file name to clipboardExpand all lines: README.md
+55-18Lines changed: 55 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,38 @@
1
1
# SortableJS-vue3
2
2
3
-
This is a thin wrapper around the great [SortableJS](https://github.com/SortableJS/Sortable) library. I had many issues migrating from Vue.Draggable to vue.draggable.next, and after briefly investigating I decided that it was too complicated and a smaller solution was the answer. This wrapper tries to keep you as close to Sortable and vanilla JS as possible. Note that this library is small enough (see https://github.com/MaxLeiter/sortablejs-vue3/blob/main/src/components/Sortable.vue) that I recommend including it in your project without using npm and importing it as a local component. All you need is the linked file.
3
+
[Demo](https://sortablejs-vue3.maxleiter.com)
4
+
5
+
6
+
This is a thin wrapper around the great [SortableJS](https://github.com/SortableJS/Sortable) library. I had many issues migrating from Vue.Draggable to vue.draggable.next, and after briefly investigating I decided that it was too complicated and a smaller solution was the answer. This wrapper tries to keep you as close to Sortable as possible (wrapper libaries seem to re-implement or unnecessarily wrap a lot of code).
7
+
8
+
Note that this library is small enough (see [Sortable.vue](https://github.com/MaxLeiter/sortablejs-vue3/blob/main/src/components/Sortable.vue) for what you really need) that I recommend including it in your project without using npm and importing it as a local component. All you need is the linked file.
9
+
10
+
### Why not use \<other library\>?
11
+
12
+
-`Vue.Draggable` only supports Vue 2
13
+
-`vue.draggable.next` uses the Options API, has multiple open (and afaict useful) pull requests, and had weird bugs/side-effects when I tried and used it
14
+
-`shopify/draggable` and [`vue-shopify-dragable`](https://github.com/zjffun/vue-shopify-draggable) seemed promising but they don't supported nested components
4
15
5
16
## Usage
6
-
You can see some demo usage at https://github.com/MaxLeiter/sortablejs-vue3/blob/main/src/components/HelloWorld.vue
17
+
You can see a demo with more complete code at [https://sortablejs-vue3.maxleiter.com](https://sortablejs-vue3.maxleiter.com).
18
+
19
+
1. Install the package:
20
+
21
+
```bash
22
+
yarn add sortablejs-vue3 sortablejs
23
+
```
24
+
25
+
or
26
+
27
+
```bash
28
+
npm install sortablejs-vue3 sortablejs
29
+
```
30
+
31
+
2. Import the component in your `<script setup>` (or `<script>`):
32
+
```typescript
33
+
import { Sortable } from'sortablejs-vue'
34
+
```
7
35
8
-
1.`yarn add sortablejs-vue3 sortablejs` or `npm install sortablejs-vue3 sortablejs`
9
-
2. Import the component in your `<script setup>`: `import { Sortable } from 'sortablejs-vue'`
10
36
3. Use the component:
11
37
12
38
```typescript
@@ -16,18 +42,6 @@ You can see some demo usage at https://github.com/MaxLeiter/sortablejs-vue3/blob
16
42
:list="elements"
17
43
item-key="id"
18
44
:options="options"
19
-
@change="logEvent"
20
-
@choose="logEvent"
21
-
@unchoose="logEvent"
22
-
@start="logEvent"
23
-
@end="logEvent"
24
-
@add="logEvent"
25
-
@update="logEvent"
26
-
@sort="logEvent"
27
-
@remove="logEvent"
28
-
@filter="logEvent"
29
-
@move="logEvent"
30
-
@clone="logEvent"
31
45
>
32
46
<template #item="{element, index}">
33
47
<divclass="draggable" :key="element.id">
@@ -40,10 +54,33 @@ You can see some demo usage at https://github.com/MaxLeiter/sortablejs-vue3/blob
40
54
41
55
4. The `list` and `item-key` props are necessary. The `options` prop is an object that can contain any SortableJS option. You can find a full list of them here: https://github.com/SortableJS/Sortable#options
42
56
57
+
### Events
58
+
You can listen to Sortable events by adding the listeners to the `Sortable` component. For example:
0 commit comments