So in the end i made this:
<select1
:selected="{ id: book.id, name: book.name }"
v-model:id="book.id"
v-model:name="book.name"
urldata="url/to/get/options"
></select1>
And my component look like this:
<template>
<div>
<select v-model="selected" @change="change" class="form-select">
<option v-for="option in options" :value="option">
{{ option.name }}
</option>
</select>
</div>
</template>
export default {
name: "select1",
emits: ["update:selected", "update:id", "update:name"],
props: {
selected: Object,
urldata: String,
},
data: function () {
return {
options: [],
};
},
mounted() {
this.GetListData();
},
methods: {
GetListData() {
if (this.urldata !== "") {
axios
.get(`${this.urldata}`)
.then((response) => (this.options = response.data.results));
}
},
change(event) {
console.log(this.selected);
this.$emit("update:selected", this.selected);
this.$emit("update:id", this.selected.id);
this.$emit("update:name", this.selected.name);
},
},
};