[Vuejs]-(Vue.js + VUEX) Commit inside Action promise not running

0👍

changing the action to be async and have an await, instead of creating the “new Promise” myself, solved the issue. Now the commit is actually executed (even though no errors were emitted on the first version + errors would be emitted if I changed the name of the commit to something invalid )

 async add({ commit }, space ) {
    return await axios.post('/spaces',space).then(
        response => {   
            commit('ADD_SPACE',response.data);    
            Promise.resolve(response.data);                
        },
        error => {                  
            Promise.reject(error);          
        });         
},

If anyone has a explanation to this tho, as I didn’t understand the reason completely.

Leave a comment