Skip to content

Instantly share code, notes, and snippets.

@psolru
Last active November 4, 2019 13:58
Show Gist options
  • Save psolru/a3730710006e44a2cfdbf42ee936d464 to your computer and use it in GitHub Desktop.
Save psolru/a3730710006e44a2cfdbf42ee936d464 to your computer and use it in GitHub Desktop.
Vue Component Wrapper for https://harvesthq.github.io/chosen/
Vue.component("chosen-select",{
props: ['value', 'multiple'],
template:'<select :multiple="multiple"><slot></slot></select>',
mounted() {
var that = this
$(this.$el)
.val(this.value)
.chosen({ width: "100%" })
.on("change", function(e) {
that.$emit('input', $(that.$el).val())
})
},
watch:{
value(val) {
$(this.$el).val(val).trigger('chosen:updated');
}
},
destroyed() {
$(this.$el).chosen('destroy');
}
})
<chosen-select v-model="user" data-placeholder="Choose a user...">
<option value="1">User 1</option>
<option value="2">User 2</option>
<option value="3">User 3</option>
</chosen-select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment