Skip to content

Instantly share code, notes, and snippets.

@techbysalma
Last active April 19, 2022 14:35
Show Gist options
  • Select an option

  • Save techbysalma/83eee7ba7e45396632d4d6e3376fd8d8 to your computer and use it in GitHub Desktop.

Select an option

Save techbysalma/83eee7ba7e45396632d4d6e3376fd8d8 to your computer and use it in GitHub Desktop.
emit an event composition api
// 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