Skip to content

Instantly share code, notes, and snippets.

@saitergun
Created March 11, 2020 19:09
Show Gist options
  • Save saitergun/00a3d8159543b2b876777d8928704d28 to your computer and use it in GitHub Desktop.
Save saitergun/00a3d8159543b2b876777d8928704d28 to your computer and use it in GitHub Desktop.
<template>
<span>
<!-- credits from https://github.com/vuejs/vuex/issues/863#issuecomment-329510765 -->
</span>
</template>
<script>
import { mapState, mapActions, mapMutations } from 'vuex';
export default {
props: ['namespace'],
computed: mapState({
state(state) {
return state[this.namespace];
},
someGetter(state, getters) {
return getters[`${this.namespace}/someGetter`];
},
}),
methods: {
...mapActions({
someAction(dispatch, payload) {
return dispatch(`${this.namespace}/someAction`, payload);
},
}),
...mapMutations({
someMutation(commit, payload) {
return commit(`${this.namespace}/someMutation`, payload);
},
}),
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment