I would like to create a reusable component that consists of two dropdowns. For the dropdowns I'm using vue-select and I would like to be able to bind the two dropdowns value into a single variable. This is so far what I've done:
ReusableMultiDroddown.vue
<template>
<div class="container">
<div class="row">
<div class="input-group">
<div class="col-md-6">
<v-select
placeholder="Dropdown1"
:options="options1"
:value="value.month"
ref="dd1"
v-model="selected1"
@input="update()"></v-select>
</div>
<div class="col-md-6">
<v-select
placeholder="Dropdown1"
:options="options1"
:value="value.year"
ref="dd2"
v-model="selected2"
@input="update()"></v-select>
</div>
</div>
</div>
</div>
</template>
<script>
import vSelect from 'vue-select';
export default {
props: ['value'],
components: {
'v-select' : vSelect,
},
data() {
return {
selected1: '',
selected2: '',
options1: [
{
label: "one",
value: 1
},
{
label: "two",
value: 2
}
]
}
},
methods: {
update() {
console.log(selected1);
console.log(selected2);
this.$emit('input', {
month: +this.$refs.dd1.value,
year: +this.$refs.dd2.value
})
}
}
}
</script>
I just can't get the value of 'value' to be binded to main v-model
Here is how I would like to use on parent component
ParentComponent.vue
<template>
<div class="container">
<rmd v-model="date" ></rmd>
</div>
</template>
<script>
import ReusableMultiDropDown from '../common/ReusableMultiDropDown.vue'
export default {
components: {
'rmd': ReusableMultiDropDown
},
data() {
return {
date: {
month: 1,
year: 2017
}
}
}
}
</script>
So whenever any of the two dropdown is changed, my variable on parent component is also changed
v-selectcomponent come from?