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)
複製程式碼