Привязать vue-multiselect к form
Как из vue-multiselect передать значение value в форму
<template>
<div>
<multiselect v-model="value"
placeholder="Выберите группу" label="name" track-by="name"
:options="options" :multiple="true"
:taggable="true"
@tag="addTag"></multiselect>
</div>
</template>
<script>
import Multiselect from 'vue-multiselect';
import axios from 'axios';
// register globally
export default {
components: {
Multiselect
},
model: {
prop: 'modelValue',
event: 'change'
},
props: {
apiUrl: {
type: String,
},
data: {
type: Array,
},
emptyValue: {
type: String,
default:null
},
customField: {
default: null
},
modelValue: {
default: null
},
selectClass: {
default: null
},
withNoValue: {
default: true
},
required: {
type: Boolean,
default: false
},
disabledOptions: {
default: () => []
},
useSlot: {
type: Boolean,
default: false
}
},
data: function () {
return {
isWaiting: false,
selectData: null,
value: [
],
options: []
}
},
created: function() {
this.loadData();
},
watch: {
apiUrl: function() {
this.loadData();
},
data:function() {
this.loadData();
},
},
methods: {
addTag (newTag) {
const tag = {
name: newTag,
code: newTag.substring(0, 2) + Math.floor((Math.random() * 10000000))
}
},
loadData: function() {
var self = this;
this.isWaiting = true;
if (this.apiUrl) {
axios.get(this.apiUrl, {
params: {
page: 1,
per_page: 100
}
}).then((response) => {
self.options = response.data.data
self.isWaiting = false;
self.$emit('loaded', self.options.length > 0 ? self.options[0].id : null);
});
}else{
self.options = self.data;
self.isWaiting = false;
self.$emit('loaded', self.options.length > 0 ? self.options[0].id : null);
}
},
onChange(e) {
this.$emit('change', e.target.value);
}
}
}