The use of vuex state tree

 export const state = () => ({
   wishNum: 0
  });
 export const mutations = {
  SET_WISH: (state) => {
     state.wishNum = 0;
 },
}

 let Num = res.total;
 setStore("wishNum", Num);

-sharp-sharp
whether I am writing this correctly. I can"t get the value of $store.state.user.wishNum. The local value is changing, but it"s still 0.

Apr.24,2021

is not $store.state.wishNum?


are state and mutations in the same file?
you can write state.js separately

export default {
    wisNum: 0
}

mutations.js

export default {
    SET_WISH: (state, payload) => {
        state.wishNum = payload
    }
}

in index.js

import state from './state.js'
import mutations from './mutations.js'
export default new Vuex.Store({
    state, mutations
})

in the Vue component

this.$store.commit('SET_WISH', 12)

in main.js

import store from './store/index.js'
new Vue({
  el: '-sharpapp',
  router,
  components: { App },
  template: '<App/>',
  store
})
Menu