Access values from emit event directly

I have a child component that emits a callback with a parameter

In the parent component:

<my-child-component @success="doSomething" />

In my child component:

this.$emit('success', response);

What I would like to do is something like this:

<my-child-component @success="someObject = response" />

Is this possible without having to create a method in the parent component? If so, how would I go about doing this?

I figured out I can do this:

<my-child-component @success="(response) => someObject = response.data" />

Hi. I think you can use the $event variable.

@success="someObject = $event"

That’s good to know. I tried using it but $event.request.response came back as a stringified object and threw an error about it being a string. I’ll have to keep experimenting.

Thanks @johandalabacka.

1 Like