Skip to content

Instantly share code, notes, and snippets.

@asika32764
Created February 20, 2019 14:02
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 asika32764/754e366423da4c9f18bfdd51661f60a5 to your computer and use it in GitHub Desktop.
Save asika32764/754e366423da4c9f18bfdd51661f60a5 to your computer and use it in GitHub Desktop.
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