[Vuejs]-Vuex store unable to update component data

0👍

The problem is in your store.js file. You are setting the default state for currentStory to Number. Setting it to an actual number instead should solve your problem:

export const store = new Vuex.Store({
  state: {
    currentStory: 0
  },
  mutations: {
    setCurrentStory(state, ID) {
      state.currentStory = ID
    }
  },
  getters: {
    currentStory: state => state.currentStory
  }
})

Additionally, in story.vue, it is unnecessary to specify storyID in the data as you already have it as a computed property (there might be an error thrown for duplicate keys)

Leave a comment