Search code examples
javascriptvue.jsevent-handlingdom-eventsevent-bubbling

Difference between @click="$emit("myFunction")" and @click="emitFunction"


Is there any difference between two of them? And which one is best practice?

enter image description here


Solution

  • No, there is no difference between them, both of them do the same thing, they emit an event to the parent component.

    As for which one is the best practice, I would say the second one, because it is more customisable, looks simpler, and if you name your function better, like emitFormSubmitted, or something similar it reads way more easier.

    Also the second option leaves possibility to do some actions before emitting, like checking validity, changing state, etc.