vue-smooth-dnd-next
vue-smooth-dnd-next
Vue 3 Wrapper of smooth-dnd library.
Live demo
NOTE: This is a Vue 3 wrapper over smooth-dnd library. It's a fork of the already done vue2 wrapper done by the original author of the library.
All the documentation for the Vue 2 version works with this package version too!
Install
npm install vue-smooth-dnd-next
Usage
<template>
<div>
<span>Studio Ghibli Tier List</span>
<Container @drop="onDrop">
<Draggable v-for="(item, i) in items" :key="item.id">
<div>
{{i + 1}} -> {{item.data}}
</div>
</Draggable>
</Container>
</div>
</template>
<script>
import { Container, Draggable } from "vue-smooth-dnd-next";
export default {
name: "app",
components: { Container, Draggable },
data() {
return {
items: [
{ id: 1, data: "Princess Mononoke" },
{ id: 2, data: "Spirited Away" },
{ id: 3, data: "My Neighbor Totoro" },
{ id: 4, data: "Howl's Moving Castle" }
]
};
},
methods: {
onDrop(dropResult){
this.items = this.applyDrag(this.items, dropResult);
},
applyDrag(arr, dragResult){
const { removedIndex, addedIndex, payload } = dragResult;
if (removedIndex === null && addedIndex === null) return arr;
const result = [...arr];
let itemToAdd = payload;
if (removedIndex !== null) {
itemToAdd = result.splice(removedIndex, 1)[0];
}
if (addedIndex !== null) {
result.splice(addedIndex, 0, itemToAdd);
}
return result;
}
}
}
</script>
Related Packages
vue-drag-n-drop
A simple kanban board where the items can be dragged and dropped from the list....
3,460
198
vue3-smooth-dnd
Drag & drop / sortable components for Vue 3. Bundles a maintained fork of smooth...
985,733
217
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 0.0.7 | ^3 | MIT | |
| 0.0.6 | ^3 | MIT | |
| 0.0.5 | ^3.5.5 | MIT | |
| 0.0.4 | ^3.5.4 | MIT | |
| 0.0.3 | ^3.0.11 | MIT | |
| 0.0.2 | ^3.0.11 | MIT | |
| 0.0.1 | ^3.0.11 | MIT |