S
S
SM_ST2021-02-03 22:39:32
Vue.js
SM_ST, 2021-02-03 22:39:32

How to update a variable in a component from store?

in the modal I write the selected category to the store like this

getCategory(category) {
      this.$store.commit('categories/SELECT_CATEGORY', category)
    },


store categories.js itself

export const state = () => ({
  categories: [],
  category: [],
})

export const mutations = {
  SELECT_CATEGORY(state, category) {
    state.category = category
  },
}


how to update the category_id variable in data() in another component

data(){
  return{
     category_id: 0
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2021-02-04
@SM_ST

Have you even read the theory ?
For a property to be automatically updated from the value in the store, it must be computed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question