Store.dispatch

分发 action。返回一个解析所有被触发的 action 处理器的 Promise。详细介绍

参数说明
参数类型必填说明
typeString类型
payloadany载荷,传入的额外参数
示例
  1. // store.js
  2. import createStore from 'chameleon-store'
  3. const store = createStore({
  4. state: {
  5. count: 0
  6. },
  7. mutations: {
  8. increment (state) {
  9. state.count++
  10. }
  11. },
  12. actions: {
  13. incrementAsync ({ commit }) {
  14. setTimeout(() => {
  15. commit('increment')
  16. }, 1000)
  17. }
  18. }
  19. })
  20. export default store
  21. // app.js
  22. store.dispatch('incrementAsync')