vue组件中使用mutations
module/numIndex.js
const numIndex = {
state: {
num: 0
},
mutations: {
SET_NUM: (state, index) => {
state.num = index
}
}
}
export default numIndex
getters.js
const getters = {
numIndex: state => state.numIndex.num
}
export default getters
vue组件中使用
import store from '@/store' // 引入store
this.$store.commit('SET_NUM', index)