I am building an interface using Vue.js. I have a form, this form contains an address, and other bits of miscellaneous data. So I created two components in Vue, UserData and UserAddress. UserData contains an instance of UserAddress as a child component. I want to specialize the behaviour of the "Submit" button for the form depending on the page, so these components don't contain the submit button -- the outer component, representing the page (UserPage) contains the submit button, and just includes the UserData template.
So the hierarchy goes, UserPage => UserData => UserAddress.
Now I need to get ALL the form data within some method on UserPage. I would just say that I need to get it within the submit handler, but the only way that I can think to do this without directly accessing the data of the child components is the following:
- Use
$broadcastto propagate an evente1downwards from the submit handler - Listen for the
e1event inUserAddress - Use
$dispatchto send an evente2and bundle the address data with the message - Listen for
e2inUserData, add the other form data to the message, and propagate or re-dispatch the event - Listen for
e2inUserPageand find the full aggregated data there.
Is this a normal method for dealing with a situation like this? It seems like overkill, but accessing child $data is explicitly non-recommended by the manual.