vue-sortable-list

0.1.2 • Public • Published

vue-sortable-list

Directive which makes your Vue list draggable.

  • Touch support
  • Handle support

Examples at codesandbox: https://codesandbox.io/s/1yplrk6kw7

Requirements
  • Vue ^2.0
Installation

From npm:
npm i -S vue-sortable-list

Usage

Register the directive:

import VDraggable from 'vue-sortable-list'
Vue.use(VDraggable)

Use v-draggable attribute on any list element (e.g. <ul v-draggable="{value: items}">), and have value reference to your items list in your data object.

Examples

Script
data: () => ({
  items = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven']
})
HTML

Without handle:

<ul v-draggable="{value: items}">
  <li v-for="item in items" :key="item">{{ item }}</li>
</ul>

With handle:

<ul v-draggable="{value: items, handle: 'handle'}">
  <li v-for="item in items" :key="item">
    <span class="handle">||</span>
    {{ item }}
  </li>
</ul>

With depth:

<div v-draggable="{value: items, depth: 1}">
  <ul>
    <li v-for="item in items" :key="item">{{ item }}</li>
  </ul>
</div>

API

v-draggable={value: items, handle: 'handle', placeholderClass: 'placeholder'}

Props
  • {Array} value - array of list items
  • {String} handle - class used by handle element
  • {String} [placeholderClass = 'v-draggable__placeholder'] - class used by placeholder element
  • {Number} depth - determines how deep is list element nested
Events

start - on drag start
end - on drag end
change - list updated - { from, to }

Package Sidebar

Install

npm i vue-sortable-list

Weekly Downloads

133

Version

0.1.2

License

ISC

Unpacked Size

7.87 kB

Total Files

4

Last publish

Collaborators

  • traxo