Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between this.$parent.$emit and this.$emit

When we need a custom component to emit an event in VueTable2, we must use:

this.$parent.$emit('myCustomEvent')

// instead of
this.$emit('myCustomEvent')

This thread tells us more about this aspect.

I used to run this.$emit() when I had to trigger an event. I was wondering what are the main differences between the two of them?

like image 486
Julien Le Coupanec Avatar asked Jul 17 '17 12:07

Julien Le Coupanec


People also ask

What is this emit in Vue?

Vue $emit is a function that lets us emit, or send, custom events from a child component to its parent. In a standard Vue flow, it is the best way to trigger certain events.

How do you emit props in Vue?

The correct way to use props and $emit Following is the flow what vue design. Parent has data to control, pass data to child component by props. If child component need to deal with props data, assign props data value to itself's data when component mounted. After handle method, parent open a interface to child.


1 Answers

this.$emit dispatches an event to its parent component.

this.$parent gives you a reference to the parent component.

As you might have guessed, this.$parent.$emit will make the parent dispatch the event to its parent.

like image 107
Ikbel Avatar answered Oct 10 '22 02:10

Ikbel