Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
            })
        }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #vuex #state #action
ADD COMMENT
Topic
Name
3+3 =