Define custom directives for binding, e.g. select2
option 1:
Vue.directive('selecttwo', {
twoWay: true,
bind: function () {
$(this.el).select2()
.on("select2:select", function(e) {
this.set($(this.el).val());
}.bind(this));
},
update: function(nv, ov) {
$(this.el).trigger("change");
}
});
use v-selecttwo for binding
option 2:
Vue.directive('select2', {
inserted(el) {
$(el).on('select2:select', () => {
const event = new Event('change', { bubbles: true, cancelable: true });
el.dispatchEvent(event);
});
$(el).on('select2:unselect', () => {
const event = new Event('change', {bubbles: true, cancelable: true})
el.dispatchEvent(event)
})
},
});
use v-select2 for binding