D
D
danilr2019-03-04 12:15:33
JavaScript
danilr, 2019-03-04 12:15:33

How to trigger vuex store mutation from component if vuex is split into modules?

I don’t understand how to cause a mutation from a component:
vuex itself

export default new Vuex.Store({
  modules: {
    residentials,
    administration
  }
})

administration module:
import { HTTP, Routes } from '@/components/Server/API'

export default{
  // namespaced: true,
  state:{
    usersInGroup: {},
    groups: [],
    roles: [],
    users: 3
  },
  actions:{
  },
  mutations:{
    getUsersinGroup(state) {
      console.log('data');
      HTTP.post(Routes.getUsersinGroup, {})
        .then(({ data }) => {
          state.usersInGroup = data;
          state.groups = data.groups;
          state.roles = data.roles;
          state.users = data.users;
          console.log(data);
        })
        .catch(error => {
          console.error(error);
        });
    }

  }
}

and so I cause a mutation in the component:
mounted() {
    console.log(this.$store.state.administration.users); // это для теста( работает)
    
    this.$store.commit.administration('getUsersinGroup') // тут не работает, как правильно вызвать
    
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Skorokhodov, 2019-03-04
@danilr

If namespaces are not specified - this.$store.commit('getUsersinGroup');
https://vuex.vuejs.org/en/guide/modules.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question