Skip to content

Help: unknown mutation type: products/openDialog #618

@Chalkin

Description

@Chalkin

I'm traying to figure out how to work with namespaced modules in vuex. But I always get the error "unknown mutation type: products/openDialog" when I try to do a commit in my vuejs instance "this.$store.commit('products/openDialog');" and when I try to call a getter inside my computed property I get undefined "this.$store.getters['products/getDialogOpen']"

store/index.js

import Vuex from 'vuex'

import products from './modules/products';
import manufacturers from './modules/manufacturers';

const store = new Vuex.Store({
  modules: {
    products
  },
  strict: process.env.NODE_ENV !== 'production'
});

export default store;

store/modules/products.js

...
const state = {
  items: [],
  dialogOpen: false
};

const mutations = {
  closeDialog() {
    state.dialogOpen = false;
  },
  openDialog() {
    state.dialogOpen = true;
  }
};
...
const getters = {
  getDialogOpen: state => {
    return state.dialogOpen;
  },
...
};

export default {
  namespaced: true,
  state,
  mutations,
  getters,
  actions
}

Vue Instance

...
computed: {
   showDialog: {
       return this.$store.getters['products/getDialogOpen'];
   }
},

....
methods: {
   onClose() {
        this.$store.commit('products/closeDialog');
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    need reproReproduction code is required

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions