Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Emit not registering in VueJS?

I was trying to make a simple function in the parent element that updates a variable when it gets an emit from the child element. I’ve been stuck on it for 2 hours and I’m fed up because I know that the answer will be so simple.

Code in question:

Child element:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div v-on:click="$emit('event1')">
      Click
</div>

Parent element:

<p @event1="test()"></p>
<Section /> // the child element

methods: {
   test() {
       console.log("test")
   },
}

The code above doesn’t log anything. I’ve made it as minimal because no outside factor would change the outcome of the code.

Thanks in advance!

>Solution :

The event listener has to be attached to your <Section /> element, event1 is not emitted globally

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading