你在组件中使用 this.$store.dispatch('xxx') 分发 action,或者使用 mapActions 辅助函数将组件的 methods 映射为 store.dispatch 调用(需要先在根节点注入 store):

import { mapActions } from 'vuex'

export default {
    // ...
    methods: {
        ...mapActions([
        'increment', // 将 `this.increment()` 映射为 `this.$store.dispatch('increment')`

        // `mapActions` 也支持载荷:
        'incrementBy' // 将 `this.incrementBy(amount)` 映射为 `this.$store.dispatch('incrementBy', amount)`
        ]),
        ...mapActions({
          add: 'increment' // 将 `this.add()` 映射为 `this.$store.dispatch('increment')`
        }),
        ...mapActions({
          add1: 'user/increment', // 将 `this.add()` 映射为 `this.$store.dispatch('user/increment')`
        add2: 'depart/increment' // 将 `this.add()` 映射为 `this.$store.dispatch('depart/increment')`
        }),
    }
}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2021-05-21
  • 2021-06-21
  • 2022-12-23
  • 2022-01-21
猜你喜欢
  • 2021-09-25
  • 2023-03-19
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2021-11-03
  • 2021-05-27
相关资源
相似解决方案