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