Last active
November 29, 2021 08:18
-
-
Save designeng/02a397986623931b43721abbc7195aca to your computer and use it in GitHub Desktop.
Emit event on selector option click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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