Search code examples
vuejs2electronvuex

Vue CLI Plugin Electron Builder dispatching vuex actions fails


I have a Vue Electron app created with Vue CLI Plugin Electron Builder and I try to integrate vuex, having the following store structure enter image description here

import Vue from "vue";
import Vuex from "vuex";
import { createPersistedState, createSharedMutations } from "vuex-electron";

import user from "./modules/user";

const debug = process.env.NODE_ENV !== "production";

Vue.use(Vuex);

// eslint-disable-next-line no-console
console.log(user);

export default new Vuex.Store({
  modules: {
    user
  },
  plugins: [createPersistedState(), createSharedMutations()],
  strict: debug
});

when I try to dispatch actions in App.vue

 created() {
    const userInDb = UserCotroller.getUser();
    this.$store.disptach("setUser", userInDb);
}

I get "TypeError: this.$store.disptach is not a function"

How do I use vuex in this setup?


Solution

  • you have a typo there:

    created() {
        const userInDb = UserCotroller.getUser();
        this.$store.disptach("setUser", userInDb);
    }
    

    change this to:

    created() {
        const userInDb = UserCotroller.getUser();
        this.$store.dispatch("setUser", userInDb);
    }
    

    you wrote disptach instead of the correct one dispatch