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贡献1824条经验 获得超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
提交
取消