- 概念与actions一样
- 可以是异步的
- 通过
store.dispatch("action名",参数)进行调用
实例
This may look silly at first sight: if we want to increment the count, why don’t we just call store.commit('increment') directly? Remember that mutations have to be synchronous. Actions don’t. We can perform asynchronous operations inside an action:
actions: {
incrementAsync ({ commit }) {
setTimeout(() => {
commit('increment')
}, 1000)
}
}Actions are triggered with the store.dispatch method:
store.dispatch('increment')Actions support the same payload format and object-style dispatch:
// dispatch with a payload
store.dispatch('incrementAsync', {
amount: 10
})
// dispatch with an object
store.dispatch({
type: 'incrementAsync',
amount: 10
})