Gathering detailed insights and metrics for vue3-sortablejs
Gathering detailed insights and metrics for vue3-sortablejs
Gathering detailed insights and metrics for vue3-sortablejs
Gathering detailed insights and metrics for vue3-sortablejs
sortablejs-vue3
[Demo](https://sortablejs-vue3.maxleiter.com) | [npm](https://www.npmjs.com/package/sortablejs-vue3)
vue-draggable-plus
Universal Drag-and-Drop Component Supporting both Vue 3 and Vue 2
element-plus-table-dragable
A directive what used sortablejs to add drag support for element-plus's table component base on vue3.
@xfc/vue3-draggable
draggable component for vue3
↕️ Re-orderable drag-and-drop lists, via a Vue directive.
npm install vue3-sortablejs
Typescript
Module System
Node Version
NPM Version
72.6
Supply Chain
99.3
Quality
75.5
Maintenance
100
Vulnerability
100
License
JavaScript (92.44%)
Vue (7.56%)
Total Downloads
40,493
Last Day
18
Last Week
476
Last Month
1,936
Last Year
25,860
22 Stars
31 Commits
2 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Jun 04, 2025
Minified
Minified + Gzipped
Latest Version
1.0.7
Package Id
vue3-sortablejs@1.0.7
Unpacked Size
16.00 kB
Size
4.20 kB
File Count
6
NPM Version
6.14.18
Node Version
14.21.3
Published on
Jun 22, 2023
Cumulative downloads
Total Downloads
Last Day
157.1%
18
Compared to previous day
Last Week
-13%
476
Compared to previous week
Last Month
-14.2%
1,936
Compared to previous month
Last Year
105.3%
25,860
Compared to previous year
Re-orderable drag-and-drop lists, via a Vue directive. Based on and offering all features of Sortable.
Several Vue wrappers for Sortable exist out there, yet I decided to build another one.
The goal was to have a wrapper that:
As a reference, here are other Sortable wrappers:
vuedraggable
only supports Vue 2vuedraggable@next
supports Vue 3, but adds a lot of overhead on top of Sortablevue-sortable
is totally outdated (last update is from 2016)sortablejs-vue3
is the best wrapper I found, but only works as a componentGet Vue 3 Sortable from jsDelivr or UNPKG and use it like this:
1<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> 2<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script> 3<script src="https://unpkg.com/vue3-sortablejs/dist/vue3-sortablejs.global.js"></script> 4 5<div id="app"> 6 <div v-sortable> 7 <div>a</div> 8 <div>b</div> 9 <div>c</div> 10 </div> 11</div> 12 13<script> 14 const { createApp } = Vue; 15 16 const app = createApp(); 17 18 app.use(sortablejs); 19 20 app.mount("#app"); 21</script>
Vue 3 Sortable is also available through npm as the vue3-sortablejs
package.
Install the package:
1npm install --save vue3-sortablejs
Register the plugin in App.vue
:
1import VueSortable from "vue3-sortablejs"; 2 3app.use(VueSortable);
And then use it like this in MyComponent.vue
:
1<template> 2 <h1>My Component</h1> 3 4 <div v-sortable> 5 <div>a</div> 6 <div>b</div> 7 <div>c</div> 8 </div> 9</template>
You can pass an object of options, in order to affect the behavior of the directive:
disabled
whether to disable the drag-and-drop behavioroptions
an object containing any Sortable option1<template> 2 <div v-sortable="{ disabled: false, options: { animation: 250, easing: 'cubic-bezier(1, 0, 0, 1)' } }"> 3 <div>a</div> 4 <div>b</div> 5 <div>c</div> 6 </div> 7</template>
A custom ready
event will be triggered as soon as Sortable is registered on the component. You can use it to access the underlying Sortable instance.
As well, you can listen to any native Sortable event.
@ready
: Sortable is ready and attached to the component@choose
: element is chosen@unchoose
: element is unchosen@start
: element dragging started@end
: element dragging ended@add
: element is dropped into the list from another list@update
: changed sorting within list@sort
: called by any change to the list (add / update / remove)@remove
: element is removed from the list into another list@filter
: attempt to drag a filtered element@move
: event when you move an item in the list or between lists@clone
: called when creating a clone of element@change
: called when dragging element changes position1<template> 2 <div v-sortable @ready="onReady" @end="onOrderChange"> 3 <div>a</div> 4 <div>b</div> 5 <div>c</div> 6 </div> 7</template> 8 9<script> 10export default { 11 methods: { 12 onReady(event) { 13 console.log(event.sortable); 14 }, 15 16 onOrderChange(event) { 17 console.log(event.oldIndex); 18 console.log(event.newIndex); 19 } 20 } 21}; 22</script>
This wrapper only impacts the actual DOM order, it does not mutate the data order. This avoids a lot of overhead in the code, and gives you the full control on your data.
It is really simple to change the order in your data after an item is dropped:
1<template> 2 <div v-sortable @end="onOrderChange"> 3 <div v-for="item in items"> 4 {{ item }} 5 </div> 6 </div> 7 8 <span>Items data: {{ items }}</span> 9</template> 10 11<script> 12export default { 13 data() { 14 return { 15 items: [ "a", "b", "c" ] 16 } 17 }, 18 19 methods: { 20 onOrderChange(event) { 21 // Remove item from old index 22 let item = this.items.splice(event.oldIndex, 1)[0]; 23 24 // Insert it at new index 25 this.items.splice(event.newIndex, 0, item); 26 } 27 } 28}; 29</script>
It is highly recommended to set a key on the children items, to help Sortable track the DOM:
1<template> 2 <div v-sortable> 3 <div key="a">a</div> 4 <div key="b">b</div> 5 <div key="c">c</div> 6 </div> 7</template>
In the same way, if you use the group
option, it is highly recommended to set a key on the parent itself. Otherwise the DOM managed by Sortable can become out-of-sync with the actual data state. I have noticed this helps a lot when using Sortable with complex components.
The key must be based on the number of items the parent contains. This will force a re-render when an item is added / removed, and make Sortable re-initialize and start from a clean state every time. This may seem a bit hacky, but it's the only way to keep a consistant behavior.
1<template> 2 <h1>Foo</h1> 3 4 <div v-sortable="{ options: { group: 'items' } }" @end="onOrderChange" :key="fooItems.length"> 5 <div v-for="item in fooItems" :key="item"> 6 {{ item }} 7 </div> 8 </div> 9 10 <h1>Bar</h1> 11 12 <div v-sortable="{ options: { group: 'items' } }" @end="onOrderChange" :key="barItems.length"> 13 <div v-for="item in barItems" :key="item"> 14 {{ item }} 15 </div> 16 </div> 17</template> 18 19<script> 20export default { 21 methods: { 22 onOrderChange(event) { 23 // Mutate fooItems and barItems 24 } 25 } 26}; 27</script>
vue3-sortablejs is released under the MIT License. See the bundled LICENSE file for details.
No vulnerabilities found.
No security vulnerabilities found.