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

How do I emit multiple arguments via setup()?

I have the following function being passed as an emit to the component:

setTray(tray, pk) {
  alert(tray)
  alert(pk)
},

Calling inside a component, I am able to reach the function, but not the arguments:

setup(props, ctx) {
  ctx.emit('setTray', 'profile-task', pk)
  ctx.emit('setTray', {tray: 'profile-task', pk: pk})
}

Both approaches result in the arguments being undefined when setTray() is executed. What is the correct syntax in this situation?

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

>Solution :

The emit function accepts one or two arguments, the event name and the payload which in your case should be defined as object :

ctx.emit('setTray', {tray: 'profile-task', pk: pk})

in parent :

setTray({tray, pk}) {//destruct the payload
  alert(tray)
  alert(pk)
},

or in old way :

setTray(payload) {
  alert(payload.tray)
  alert(payload.pk)
},
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