Skip to content

Instantly share code, notes, and snippets.

@suth

suth/sortable.js

Created Jan 26, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.