Answer the question
In order to leave comments, you need to log in
Why doesn't rootState work?
There is a store with a built-in module
const counterModule = {
namespaced: true,
state() {
return {
counter: 0
};
},
getters: {
testAuth(rootState) {
return rootState.isLoggedIn;
}
}
};
const store = createStore({
modules: {
counter: counterModule
},
state() {
return {
isLoggedIn: false
};
}
});
<template>
<p>{{ isTestAuth }}</p>
</template>
<script>
export default {
computed: {
isTestAuth() {
return this.$store.getters['counter/testAuth'];
}
}
};
</script>
Answer the question
In order to leave comments, you need to log in
And why did you decide that rootState is the first argument in the module getter? Because the argument was named rootState ?
Read until fully enlightened .
UPD: Well xs, everything works for me as usual
The point is inattention or misunderstanding of what destructuring assignment is.
That's it - no need.
It should be like this, like this, like this:
getters: {
testAuth(state, getters, rootState) {
return rootState.isLoggedIn; // тут возможно нужно к isLoggedIn полный путь написать, например return rootState['myStoreModule/isLoggedIn']
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question