I've encountered an issue with my custom select component where the data prop selectedOffer
is not being set to the value selected in the dropdown, as $event
seems to be empty.
Is there a way to assign the selected value from the dropdown to selectedOffer?
offersList.vue
<dropdown
:options="userOffers"
:value="selectedOffer"
:item-title-key="'title'"
:item-value-key="'id'"
:item-id-key="'id'"
@optionSelected="setSelectedOffer($event)" />
offersList.js
data() {
return {
userOffers: [{title: 'aus ITA'},{title: 'aus DE'}],
selectedOffer: '',
};
},
methods: {
setSelectedOffer(value) {
this.selectedOffer = value;
console.log(this.selectedOffer);
},
},
dropdown.vue
<select
:id="id"
:name="name"
@change="$emit('optionSelected', $event.target.value)">
<slot/>
<option
v-for="item in options"
:title="item[itemTitleKey]"
:value="item[itemValueKey]"
:key="item[itemIdKey]">
{{ item[itemTitleKey] }}
</option>
</select>