Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mecjos's avatar

How to get a calling function in Vuex?

Hi. I would like to get the calling function of a mutation? I want to call same mutation function ( updateProjects ) from an action function to delete projects from projects store and to add new projects. Because of that I need to know which action function is calling the mutation. How Can i do that?

state : {
    projects : []
}   

mutations: {

    updateProjects () {
        if (calllingFunction == delete) {
            do delete ops..
        } elseif (callingFunction == update) {
            do update ops...
        }
}

actions : {
    deleteProject ({commit}, payload) {
        commit("updateProjects", payload)
    },
    addProject ({commit}, payload) {
        commit("updateProjects", payload)
    }
}

something like that.

0 likes
2 replies
sarav1234's avatar

I mean this question is pretty old but you could pass the string "delete" or "update" as part of the payload as a new property name action then in the mutation just use if (payload.action === 'delete') { do delete ops.. } else if (payload.action === 'update') { do update ops... }

Please or to participate in this conversation.