- 用来修改state的函数
- 只能是同步的,不能是异步的
调用该函数
commit(对应函数名)
实例
You can pass an additional argument to store.commit, which is called the payload for the mutation:
// ...
mutations: {
increment (state, n) {
state.count += n
}
}store.commit('increment', 10)In most cases, the payload should be an object so that it can contain multiple fields, and the recorded mutation will also be more descriptive:
// ...
mutations: {
increment (state, payload) {
state.count += payload.amount
}
}store.commit('increment', {
amount: 10
})