Created
March 11, 2020 19:09
-
-
Save saitergun/00a3d8159543b2b876777d8928704d28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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