Skip to content

Invoke parent/host component method from a child/encapsulated component #10765

Discussion options

You must be logged in to vote

Passing a function as a prop and passing a function as an event listener achieves pretty much the same.

The difference is mainly this: When the child emits an event, it doesn't care wether there's a listener from the parent. In other words, evetn listeners are always optional. When the child calls a function passed through a prop, the child has to make sure the function actually exists, but on the flip-side, the child can actually work with the function's return value, whereas emitting an event does not return anything in the child

Using events is the default pattern used in Vue. But passing a function as a prop can be useful sometimes, i.e. when you want to work with the function's retur…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by guysagy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants