Created
January 26, 2017 06:19
-
-
Save suth/7737ee9eefe11e8043f5449bf4f3145f to your computer and use it in GitHub Desktop.
Vue.js 2.0 Sortable Directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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