[Vuejs]-Vuejs with namespaced modules and unknow mutation type

0πŸ‘

  1. You need to remove prefixes with slash from mutation names because your modules namespaced and you will always access this mutations outside indicating a module name like this moduleName/mutation.

For instance:

const SET_BAR_IMAGE = "NAVSTORE/SET_BAR_IMAGE";
const SET_DRAWER = "NAVSTORE/SET_DRAWER";
// should be
const SET_BAR_IMAGE = "SET_BAR_IMAGE";
const SET_DRAWER = "SET_DRAWER";

  1. Because the SET_DRAWER mutation is inside a navspaces module you should call it indicating a module name:
this.$store.commit("navstore/SET_DRAWER", val);
  1. Don’t try to call actions inside actions like this:
 actionDoLogin({ dispatch }, payload) {
      return services.login(payload).then((res) => {
        dispatch("actionSetUser", res.data.user);
        dispatch("actionSetToken", res.data.token);
      });
    },

Use mutations in a desired combination:

 actionDoLogin({ dispatch }, payload) {
      return services.login(payload).then((res) => {
        commit(SET_USER, res.data.user);
        commit(SET_TOKEN, res.data.token);
      });
    },

Leave a comment