vuex在组件内派发action
我们可以用this.$store.dispatch()去派发action,也可以通过如下辅助函数的方式派发action
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')`}),}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
