Last active
November 4, 2019 13:58
-
-
Save psolru/a3730710006e44a2cfdbf42ee936d464 to your computer and use it in GitHub Desktop.
Vue Component Wrapper for https://harvesthq.github.io/chosen/
This file contains hidden or 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
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'); | |
} | |
}) |
This file contains hidden or 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
<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