mapState、mapMutations、mapActions
import { mapState, mapMutations, mapActions } from 'vuex'
computed: mapState(['count', 'count2'])
computed: {
test: 'test sss',
...mapState(['count', 'count2'])
}
methods: {
...mapMutations('m1', ['loginMutation'])
// 如果不是modules中的,直接写
...mapMutations(['loginMutation'])
}
// 使用
this.loginMutation()
// this.$store.commit('m1/loginMutation')
使用 createNamespacedHelpers 创建基于某个命名空间辅助函数
import { createNamespacedHelpers } from 'vuex'
const { mapState, mapActions } = createNamespacedHelpers('some/nested/module')