Home > Back-end >  My emit doesnt work, I cant send any data to parent
My emit doesnt work, I cant send any data to parent

Time:01-29

This is my code - child:

<a-camp :camp="camp.name" @click="$emit('camp-selected', camp)" />

export default {
    emits: ['camp-selected'],
...

parent:

<a-camp-select @camp-selected="campSelected(camp)"></a-camp-select>

When I try emit without -camp- parameter it works, I can console log test, but when I add -camp-, I cant get it to parent, I also try console log camp in child component and it works. So there is problem somewhere in the middle. Any hints?

CodePudding user response:

You should not mention the parameter when you set the handler for the emitted event @camp-selected="campSelected(camp)":

<a-camp-select @camp-selected="campSelected">

you've to mention it inside the method definition:

methods:{
  campSelected(camp){
    //use camp here 
  }
}

  •  Tags:  
  • Related