Skip to content

Instantly share code, notes, and snippets.

@designeng
Last active November 29, 2021 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save designeng/02a397986623931b43721abbc7195aca to your computer and use it in GitHub Desktop.
Save designeng/02a397986623931b43721abbc7195aca to your computer and use it in GitHub Desktop.
Emit event on selector option click
<!-- parent form component -->
<template>
<form>
<FormSelector
:options="users"
:selected="currentUser"
@change="onUserChange($event)"
/>
</form>
</template>
<script>
export default {
name: 'Form',
data () {
return {
users: [.......],
currentUser: 'John'
}
},
methods: {
onUserChange (e) {
/* do something */
}
}
}
</script>
<template>
<select
:value="selectedOption"
@change="$emit('change', $event)"
>
<option
v-for="(option, index) in options"
:key="index"
:value="option.value"
>{{ option.text }}</option>
</select>
</template>
<script>
export default {
name: 'FormSelector',
props: {
selected: {type: Number | String},
options: {type: Array},
},
computed: {
selectedOption () {
return this.selected
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment