I'm trying to pass data from a child to the parent component using an event but I'm not being able to catch it. The event is fired on a child's component function but not caught on the parent's component function.
Can someone figure out why the callbackMethod is not called?
I already tried other names using kebab-case, tried without the custom data/parameter, tried to catch the event on the template tag, tried wrapping up the child component into a div, tried to remove the parenthesis on the v-on statement...
Child Component:
HTML
<v-btn
color="primary"
icon
small
elevation="1"
@click="openSettings"
>
<v-icon>
mdi-dots-vertical
</v-icon>
</v-btn>
JavaScript
export default {
name: "ChildComponent",
components: {
OtherChild
},
props: {
my_prop: Object
},
methods: {
openSettings: function () {
// always use kebab-case for event names!
// (https://v2.vuejs.org/v2/guide/components-custom-events.html)
this.$emit("open-child-settings", this.my_prop)
console.log("event")
}
}
Parent Component:
HTML
<v-container>
<ChildComponent @open-child-settings="callbackMethod($event)"/>
</v-container>
JavaScript
export default {
name: 'ParentComponent',
components: {
ChildComponent,
OtherChildComponent
},
methods: {
callbackMethod: function (my_prop){
this.settingsDialog = true;
this.tempProp = my_prop;
console.log("callback")
}
}
Dependencies
"dependencies": {
"core-js": "^3.6.5",
"dotenv": "^8.2.0",
"vue": "^2.6.11",
"vuetify": "^2.2.11"
}
EDIT: Added the Code on a Sand Box so you can see the whole panorama and some snapshots of the Vue.js Extension: