Skip to content

Instantly share code, notes, and snippets.

@Fusseldieb
Last active March 23, 2022 03:19
Show Gist options
  • Select an option

  • Save Fusseldieb/0e2bd6af4579a37cb1dabdd8866a80b5 to your computer and use it in GitHub Desktop.

Select an option

Save Fusseldieb/0e2bd6af4579a37cb1dabdd8866a80b5 to your computer and use it in GitHub Desktop.
A custom select2 component which is ready to be used
<template>
<select :value="value" style="width: 100%">
<option value="" selected disabled>Auswählen...</option>
<option v-if="!options">{{ value }}</option>
<option v-for="option in options" :value="option.value ? option.value : option.text">
{{ option.text }}
</option>
</select>
</template>
<script>
import $ from "jquery";
import select2 from "select2";
export default {
name: "Select2",
props: ["value", "options", "tags", "format", "ajax"],
mounted: function() {
const vm = this;
$(vm.$el)
.select2({
tags: vm.tags,
// selectOnClose: true,
ajax: vm.ajax
})
// .trigger("change")
.on("change", function() {
vm.$emit("input", vm.$el.value);
});
},
watch: {
value: function(value) {
// update value
$(this.$el)
.val(value)
.trigger("change");
},
options: function(options) {
console.log(options);
console.log("Options Debug Test");
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment