Skip to content

Instantly share code, notes, and snippets.

@zdimaz
Last active December 21, 2021 11:46
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 zdimaz/de872396de45b0f474e36e020fd9d0f2 to your computer and use it in GitHub Desktop.
Save zdimaz/de872396de45b0f474e36e020fd9d0f2 to your computer and use it in GitHub Desktop.
emits vue 3 js
<!--
From the child component, you want to do an "emit".
This tells the parent to run the callback specified
in the child component reference. Psuedo code:
-->
<child>
<button @click="send()">Click Me</button>
methods: {
send() {
this.$('send', 'Hello World');
}
}
</child>
<parent>
<child @send="receive"></child>
methods: {
receive(childData) {
console.log(childData); // "Hello World"
}
}
</parent>
<!--
From the child component, you want to do an "emit".
This tells the parent to run the callback specified
in the child component reference. Psuedo code:
-->
<child>
<button @click="send()">Click Me</button>
methods: {
send() {
this.$('send', 'Hello World');
}
}
</child>
<parent>
<child @send="receive"></child>
methods: {
receive(childData) {
console.log(childData); // "Hello World"
}
}
</parent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment