Hello fellow SO Friends,
I am having problems referencing a vuex store module in one of my Vue components. I am able to get the State and Mutations working if I move the code from the authentication.module.ts to the store.ts, however when trying to use a module for cleaner code, it seems I can not make a reference to the module. I Get an error:
[vuex] module namespace not found in mapState(): @/_Store/_Modules/authentication.module/
I Have added namespaced:true to the module so I am confused what else I am missing?
Store.ts
import Vue from "vue";
import Vuex from "vuex";
import Authentication from "@/_Store/_Modules/authentication.module"
Vue.use(Vuex);
export default new Vuex.Store({
modules:{
Authentication
}
});
authentication.module.ts
Updated: Added namespace:'Authentication' - Problem still exist
export default {
namespaced:true,
namespace:'Authentication'
state: {
counter: 0
},
mutations:{
incrementCounter(state: { counter: number; }) {
state.counter++ }
}
}
Home.Vue (The Error is here when it loads since the State property is suppose to render)
<h1>Hello and Welcome Home!</h1>
<div>The Count of the store is: {{counter}}</div>
<button type="button" v-on:click='increment'>Click to Increment</button>
<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import { State, Getter, Action, Mutation, namespace } from "vuex-class";
const Authentication = namespace("@/_Store/_Modules/authentication.module"); // This is the problem line here it seems?
@Component
export default class Home extends Vue {
@Authentication.State("counter") counter!: number;
@Authentication.Mutation("incrementCounter") increment!: void;
}
</script>
Main.ts
*Updated: Added the Main.ts File for reference
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./_Store/store";
import '../node_modules/bootstrap/dist/css/bootstrap.min.css'
Vue.config.productionTip = false;
new Vue({
router,
store,
render: h => h(App),
}).$mount("#app");
namespace('Authentication')
– Giovaneexport default new Vuex.Store({ state: { }, mutations: { }, actions: { }, getters: { }, modules: { Authentication } })
Also, try exportingexport const Authentication
instead of default. – Danijel