Last active
April 19, 2022 14:35
-
-
Save techbysalma/83eee7ba7e45396632d4d6e3376fd8d8 to your computer and use it in GitHub Desktop.
emit an event composition api
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
| // child component | |
| <template> | |
| <input | |
| @keyup="getData" | |
| > | |
| </template> | |
| <script> | |
| export default { | |
| name: 'child', | |
| emits: ['search'], | |
| setup(props, { emit }) { | |
| const getData = () => { | |
| // do you... | |
| emit('search', 'bla bla bla') | |
| } | |
| return { | |
| getData, | |
| } | |
| } | |
| } | |
| </script> | |
| // parent component | |
| <template> | |
| <child @search="getBlaBla" /> | |
| <template/> | |
| <script> | |
| import Child from '...' | |
| export default { | |
| name: 'parent', | |
| components: { | |
| Child, | |
| }, | |
| setup() { | |
| const getBlaBla = (value) => { | |
| console.log(value) // output : Bla Bla Bla | |
| } | |
| return { | |
| getBlaBla, | |
| } | |
| } | |
| } | |
| <script/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment