Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
83
rated 0 times [  85] [ 2]  / answers: 1 / hits: 17177  / 4 Years ago, sun, august 2, 2020, 12:00:00

Anybody knows how to use mapState or mapGetters with Vue 3 in the setup function ?
I know that is possible to use the store with the useStore hook but with this hook We import all the store while with mapState or mapGetters we can specify a module :


// ...

computed: {
...mapGetters('myModule', [
'myStateVariable'
]
)

//...

More From » vue.js

 Answers
4

Perhaps something like this:


import { computed }  from 'vue';
import { useStore } from 'vuex';

const module = 'myModule';

export default {
setup() {
const store = useStore();

return {
// getter
one: computed(() => store.getters[`${module}/myStateVariable`],

// state
two: computed(() => store.state[module].myStateVariable,
};
},
};

[#50747] Tuesday, July 21, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
editha

Total Points: 564
Total Questions: 107
Total Answers: 109

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
;