Geoff
Geoff

Reputation: 6629

Vuejs commit to a mutation fails

This is how am performing commit but data is never passed through

const actions ={
 updateBtn({commit}, data){
  commit("test", data);
  console.log("data is"+data);//data here has a value

 }
}


const mutations={
test(state, {data}){
    console.log(data) //this is always undefined.
  }

}

Where am i going wrong in the mutations

Upvotes: 0

Views: 55

Answers (1)

agriboz
agriboz

Reputation: 4854

Try using like this without function parameter.

const actions = {
 updateBtn({commit}, data){
  commit("test", data);
  console.log({data}); // data here has a value

 }
}


const mutations = {
  test(state, data) {
    console.log({data});
    state.data = data;
  }
}

Upvotes: 1

Related Questions