Hello @vincent15000, I may be wrong but if what you want is to easily communicate between a child and parent no matter how deep the child is, then I suggest you use Pinia. Then in case you need to persist state while using Pinia, try the package below. https://github.com/prazdevs/pinia-plugin-persistedstate
VueJS multiple components and events
Hello,
It's an app with Laravel / VueJS / InertiaJS.
I have several Pages / Components which are nested together.
For example :
-
the training view (page) displays the units list (component) and the courses list (component).
-
the courses list displays the course modal form (component)
The controller displays the training view, so it sends all datas to the view (training with units and courses). When I open the course form to add / update a course, I send a request to the backend (axios request, not inertia) and I need to refresh the datas (or only a part of the datas, InertiaJS does this very well).
So the course form emits an event to the course list which emits an event to the training view and the training view sends an inertia request to refresh the datas.
I could effectively refresh the datas from the form, but the form is potentially used in other places, so it's not really a good idea to send the inertia request from the form.
I could have a same question in the other direction : the main parent pass a props to its child which passes the same props to its own child, ...
I probably need advice to better structure my VueJS components. I have seen the VueJS videos on Laracast, very useful, but when I have to pratice for a project, I encounter some other problems like child emits to parent emits to main parent, ...
Is there another way to proceed than the one where each child emits an event up to its parent until the main parent is informed and refreshes the datas ?
Thanks for your help ;).
Vincent
Please or to participate in this conversation.