vue-base-demo
Version:
vue base demo
31 lines (27 loc) • 696 B
JavaScript
// type常量
export const INCREMENT = 'INCREMENT'
export const DECREMENT = 'DECREMENT'
// 默认值
const state = {
count: 0,
history: []
}
/**
* Mutations 本质上是一个事件系统:每个 mutation 都有一个 事件名 (name) 和 一个 回调函数 (handler).
* 任何一个 Mutation handler 的第一个参数永远为所属 store 的整个 state 对象
*/
const mutations = {
[INCREMENT] (state, amount = 1) {
// 改变 state
state.count += amount
state.history.push('increment')
},
[DECREMENT] (state, amount = 1) {
state.count -= amount
state.history.push('decrement')
}
}
export default {
state,
mutations
}