I'm creating a dropdown input using simple div elements. Cause css customisation on native tag is limited.
<div class="dropdown">
<button @click="open=true">{{selected}}</button>
<div class="dropdown-content" v-if="open">
<p @click="setValue()">Hello World!</p>
<p>Hello World!</p>
<p>Hello World!</p>
</div>
</div>
So when the user clicks on the button setValue() method will be fired.
export default {
name: "dropdown",
components: {},
props: [
"value",
],
data() {
return {
selected : null }
},
computed: {},
mounted() {},
methods: {
setValue(value) {
this.open = false;
this.selected = value;
this.$emit("selected", value);
},
},
};
So my question is that how can I bind v-model to this custom component from the outside:
Like this :
<dropdown v-model="dropvalue"></dropdown>
Currently I'm listening to the emit event from the component and manually updating the input value... (something like ...<dropdown @selected="changeValue($event)"></dropdown> Instead how can I implement something like metioned above ... using v-model???