Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Vue Select2 Directive
function updateFunction (el, binding) {
Vue.nextTick(function () {
// :v-select2="{ options... }"
let options = binding.value || {};
// set up select2
$(el).select2(Object.assign({}, {
// Default options
}, options))
.on("select2:select select2:unselect", (e) => {
el.dispatchEvent(new Event('change', { target: e.target }));
});
});
}
Vue.directive('select2', {
inserted: updateFunction ,
componentUpdated: updateFunction,
});
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.