Answers for "vuex use state in action"

1

vuex use state in action

// If you want to use state in action when using Vuex store
// all you need is to add 'state' next to commit in curly bracket '{ }'

// Exapmle:

someAction({commit, state}){
            axios.get("https://myUrl.com/" + state.version )
            .then((response) => {
                commit('champions', {
                    champions: response.data.data
                })
            })
            .catch(function (error) {
                console.log(error);
            })
        }
Posted by: Guest on August-10-2021
0

vue store access state in actions

actions: {
  actionName ({ commit, state }, payload) {
    console.log(state)
  }
}
Posted by: Guest on November-09-2020

Code answers related to "vuex use state in action"

Code answers related to "Javascript"

Browse Popular Code Answers by Language