export const state = () => ({
wishNum: 0
});
export const mutations = {
SET_WISH: (state) => { state.wishNum = 0;
},
}
let Num = res.total; setStore("wishNum", Num);##我這樣寫對不對。我獲取不到$store.state.user.wishNum的值本地的值在變化然而他還是0。
2 回答

慕妹3242003
TA貢獻(xiàn)1824條經(jīng)驗 獲得超6個贊
state 和 mutations 放在一個文件中嗎?
你可以分開寫 state.js
export default { wisNum: 0}
mutations.js
export default { SET_WISH: (state, payload) => { state.wishNum = payload } }
index.js中
import state from './state.js' import mutations from './mutations.js' export default new Vuex.Store({ state, mutations })
Vue組件中
this.$store.commit('SET_WISH', 12)
main.js中
import store from './store/index.js'new Vue({ el: '#app', router, components: { App }, template: '<App/>', store })
添加回答
舉報
0/150
提交
取消