Vue Draggable ES

4.1.1 · active · verified Sun Apr 19

vuedraggable-es is a Vue.js 3 component that enables drag-and-drop functionality for lists, keeping the view model array synchronized with the HTML. It is built upon and exposes all features of Sortable.js, including touch device support, drag handles, smart auto-scrolling, and inter-list dragging. The current stable version is 4.1.1, and it is actively maintained with frequent bug fixes and feature enhancements, as seen in the recent release history. A key differentiator is its explicit compatibility with Vue 3's `transition-group` component and its focus on being an ES module, making it suitable for modern Vue projects. It also allows making existing UI library components draggable while maintaining full control via events. Its development follows the `vue.draggable.next` project, targeting Vue 3 exclusively.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic draggable list using `vuedraggable-es` with Vue 3's Composition API, `v-model` for synchronization, and event handling for drag start/end states in a single file component.

<script setup>
import draggable from 'vuedraggable-es'
import { ref } from 'vue'

const myArray = ref([
  { id: 1, name: 'Item 1' },
  { id: 2, name: 'Item 2' },
  { id: 3, name: 'Item 3' },
]);
const drag = ref(false);

function handleStart() {
  drag.value = true;
  console.log('Drag started');
}

function handleEnd() {
  drag.value = false;
  console.log('Drag ended', myArray.value);
}
</script>

<template>
  <div style="font-family: sans-serif; padding: 20px;">
    <h2>Draggable List</h2>
    <p>Drag status: {{ drag ? 'Dragging' : 'Not dragging' }}</p>
    <draggable
      v-model="myArray"
      group="people"
      @start="handleStart"
      @end="handleEnd"
      item-key="id"
      style="border: 1px solid #ccc; padding: 10px; min-height: 50px;"
    >
      <template #item="{ element }">
        <div style="background: #f9f9f9; border: 1px solid #eee; margin-bottom: 5px; padding: 8px; cursor: grab;">
          {{ element.name }}
        </div>
      </template>
    </draggable>
    <pre style="background: #eee; padding: 10px; margin-top: 20px;">{{ JSON.stringify(myArray, null, 2) }}</pre>
  </div>
</template>

view raw JSON →