[Vuejs]-Trouble getting data from root Vue instance with vue-router

0๐Ÿ‘

โœ…

I would avoid sharing the data using the router instance.
I personally like to have a store file, which contains data I want to share between my components.

export default {
  state: {
    counter: 0
  }
}

And in your component you can import the file:

import store from '../store'

export default {
  data () {
    return {
      sharedState: store.state
    }
  }
}

Changes to sharedState will also be passed to other components.

Source: https://skyronic.com/2016/01/03/vuex-basics-tutorial / Solution 2

Leave a comment