Skip to content

Instantly share code, notes, and snippets.

@suth
Created January 26, 2017 06:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suth/7737ee9eefe11e8043f5449bf4f3145f to your computer and use it in GitHub Desktop.
Save suth/7737ee9eefe11e8043f5449bf4f3145f to your computer and use it in GitHub Desktop.
Vue.js 2.0 Sortable Directive
import Vue from 'vue'
import Sortable from 'sortablejs'
Vue.directive('sortable', {
inserted: function (el, binding, vnode) {
var sortable = new Sortable(el, binding.value || {});
if (binding.arg) {
if (!vnode.context.sortable) {
vnode.context.sortable = {}
}
// Throw an error if the given ID is not unique
if (vnode.context.sortable[binding.arg]) {
console.warn('[vue-sortable] cannot set already defined sortable id: \'' + binding.arg + '\'')
} else {
vnode.context.sortable[binding.arg] = sortable
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment