[Vuejs]-Emit to Parent triggers method but not value

1πŸ‘

βœ…

It is likely you need to replace your <router-view> code with this:

  <v-content>
    <router-view v-on:displayUser="updateUser"></router-view>
  </v-content>

Note that I am no longer passing user_name in the event handler. That is because user_name is not available in your template.

You are saying On 'displayUser', call the 'updateUser' with the 'user_name' variable. But user_name is not known to your App component.

But what you mean to actually say is On 'displayUser', call the 'updateUser' method with whatever event parameters are sent back.


You may also specify the event parameters by passing $event like so:

<v-content>
  <router-view v-on:displayUser="updateUser($event)"></router-view>
</v-content>

Docs: https://v2.vuejs.org/v2/guide/events.html#Methods-in-Inline-Handlers

πŸ‘€rideron89

Leave a comment