Vue Draggable for Vue 2.x (Sortable.js Wrapper)

2.24.3 · maintenance · verified Sun Apr 19

vuedraggable is a Vue 2.x component that provides drag-and-drop functionality for lists, leveraging the robust capabilities of Sortable.js. Version 2.24.3, published over five years ago, is specifically tailored for Vue 2 applications, offering declarative list reordering, multi-drag, and nested list support. It acts as a lightweight wrapper around Sortable.js, abstracting away direct DOM manipulation and integrating seamlessly with Vue's reactivity system. While newer versions (v4.x) exist for Vue 3, this entry focuses on the 2.x branch, which received consistent maintenance and updates for features like TypeScript definitions (since 2.24.0) and SSR compatibility fixes (like in 2.23.2). Its key differentiator remains the powerful and flexible drag-and-drop mechanics inherited from Sortable.js, presented in a Vue-idiomatic way, making it a widely adopted solution for interactive list management in legacy Vue 2 projects.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates basic usage of `vuedraggable` (v2.x) to create two interconnected sortable lists in a Vue 2 application. It uses `v-model` for data synchronization, `group` for drag-and-drop between lists, and logs `start`, `end`, and `change` events to the console.

import Vue from 'vue';
import draggable from 'vuedraggable';

new Vue({
  el: '#app',
  components: {
    draggable,
  },
  data() {
    return {
      list1: [
        { id: 1, name: 'Item 1' },
        { id: 2, name: 'Item 2' },
        { id: 3, name: 'Item 3' },
      ],
      list2: [
        { id: 4, name: 'Item 4' },
        { id: 5, name: 'Item 5' },
      ],
      drag: false,
    };
  },
  methods: {
    log(evt) {
      console.log('Drag event:', evt);
    },
  },
  template: `
    <div id="app">
      <h2>List 1</h2>
      <draggable
        class="list-group"
        tag="ul"
        v-model="list1"
        group="items"
        @start="drag = true"
        @end="drag = false"
        @change="log"
      >
        <li
          class="list-group-item"
          v-for="element in list1"
          :key="element.id"
        >
          {{ element.name }}
        </li>
      </draggable>
      
      <h2>List 2</h2>
      <draggable
        class="list-group"
        tag="ul"
        v-model="list2"
        group="items"
        @start="drag = true"
        @end="drag = false"
        @change="log"
      >
        <li
          class="list-group-item"
          v-for="element in list2"
          :key="element.id"
        >
          {{ element.name }}
        </li>
      </draggable>
      <p>Dragging: {{ drag }}</p>

      <style>
        .list-group { min-height: 50px; border: 1px solid #eee; padding: 10px; margin-bottom: 20px; }
        .list-group-item { padding: 10px; margin-bottom: 5px; background-color: #f9f9f9; border: 1px solid #ddd; cursor: grab; }
        .list-group-item:active { cursor: grabbing; }
      </style>
    </div>
  `,
});

view raw JSON →