For my current project we have a single navbar.vue that is placed in a components folder. Then all our pages are listed under the layouts folder. Currently the vue app is ran by the main.js file that places the navbar on each page. Is it possible to have different data on each page that is shown in the navbar, but then these piece of information can also be treated as event clicks and toggle reactions on each page?
1 Answer
This is was vuex was made for.
Your shared application state resides in a store that manages reactivity between components.
You would get your data from the $store in you navbar and components.
I like to view the refactoring of data in vue as such:
First data in, and private to, a component
Then props passed in from parent
Then events emitted from child to parent (child never mutates data passed in, so it sends events up instead)
Then $store/state from vuex to go beyond when this parent/child model starts to fall apart.