[Vuejs]-Vue.js: When implementing the "Simple State Management from Scratch" approach, how to pass on/access the store?

0👍

Yes, you are correct.

You should declare your store in your component declaration as described here

document.js


var store = {
    debug: true,
    state: {
          message: 'Hello!'
         },
    setMessageAction (newValue) {
        if (this.debug) console.log('setMessageAction triggered with', newValue)
        this.state.message = newValue
    },

    clearMessageAction () {
        if (this.debug) console.log('clearMessageAction triggered')
        this.state.message = ''
    }
 }



var vmA = new Vue({
   data: {
    privateState: {},

    <!-- HERE YOU ARE PASSING THE STATE -->
    sharedState: store.state
    }
  })

Leave a comment