0

I'm stuck on a problem that I had already encountered and which was resolved with the namespaced but nothing helped. This is my module:

const Algo1Module = {
  namespaced: true,
  state: {
    questions: {
      question1: "test",
      question2: "",
      question3: "",
      question4: "",
      question5: "",
      question6: ""
    }
  },
  getters: {
    getMyQuestions(state) {
      return state.questions;
    }
  }
};

export default Algo1Module; // export the module

This is my index.js from my store:

import Vuex from "vuex";
import createLogger from "vuex/dist/logger";
import algo1 from "@/store/modules/algo1.store";

Vue.use(Vuex);
const debug = process.env.NODE_ENV !== "production";

export default new Vuex.Store({
  modules: {
    algo1
  },
  strict: debug,
  plugins: debug ? [createLogger()] : []
});

And i try to access to my getters from my component like this :

<script>
import { mapGetters } from "vuex";
export default {
  name: "Algo",
  computed: {
    ...mapGetters("Algo1Module", ["getMyQuestions"])
  }
};
</script> 

But i have an error message in console : [vuex] module namespace not found in mapGetters(): Algo1Module/

I don't understand or I may have made a mistake. Thank you for the answer you can give me.

2 Answers 2

2

It will take name that you set up when imported module, try algo1

Sign up to request clarification or add additional context in comments.

1 Comment

Ah yes it's my fault I really didn't see the difference in naming. Thanks a lot
2
  1. Your module name is registered under algo1 name.
  2. If you want to call it Algo1Module then register it in the store like that:
modules: {
  Algo1Module: algo1,
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.