stUrb
stUrb

Reputation: 6822

Vuex mutation does not commit payload data

I've got a simple VueJS application which uses a Vuex store:

 const store = new Vuex.Store({
    state: {
      organisatie: {}
    },
    mutations: {
      loadOrganisatie (state, payload) {
         state.organisatie = payload.organisatie;
         console.log(payload.organisatie);
      }
    }
});

From one of my components I then load the organisation's data to the store as some other components on the page also need its data:

...
created() {
   axios.get('/get/'+this.$route.params.orgId)
     .then(response => {
         this.$store.commit({
           type: 'loadOrganisatie',
           organisatie: response.data
     })
}
...

But the commited state of my Vuex store remains an empty object:

vuexstore

The payload.mutation.organisatie in the devtools is filled with the proper data. But the state.organisatie stays an empty object.

Upvotes: 3

Views: 2240

Answers (1)

Mahamudul Hasan
Mahamudul Hasan

Reputation: 2823

Hope, it will work great for you

mutations: {
      loadOrganisatie (state, payload) {
         state.organisatie = Object.assign({},payload.organisatie);
         console.log(payload.organisatie);
      }
    }

Upvotes: 2

Related Questions