[Vuejs]-Pass data from one component to all with $emit without using @click in VueJS

0👍

You can create another Javascript file which holds an Object with your initial state. Similar to how you define data in your components.

In this file your export your Object and import it in all Components which need access to this shared state. Something along the lines of this:

import Store from 'store';

data() {
  return {
    store
  }
}

This might help:

https://v2.vuejs.org/v2/guide/state-management.html

At this point if you app grows even more in complexity you might also start checking out Vuex which helps to keep track of changes(mutations) inside of your store.

The given example is essential a very oversimplified version of Vuex.

Leave a comment