Alexandre Viretti
Alexandre Viretti

Reputation: 119

Vue x module Namespace

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.

Upvotes: 0

Views: 167

Answers (2)

Adam Orłowski
Adam Orłowski

Reputation: 4464

  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,
}

Upvotes: 2

Asimple
Asimple

Reputation: 650

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

Upvotes: 2

Related Questions