Reputation: 2018
So for example, my json response looks like:
"name": "John"
"value": "5"
Then I pass it to my state
commit("SET_USER", response.data.user);
But, if name is == "John" i want the value to be 10 and pass it to mutation. Is it possible to do this?
I can access value like this response.data.user[0].value
if(response.data.user[0].name == "John") {
response.data.user[0].value == "10"
}
commit("SET_USER", response.data.users); // <-- state.cards
})
Upvotes: 0
Views: 199
Reputation: 1
You could use map
function :
commit("SET_USER", response.data.user.map(item=>{
if(item.name=='John'){
item.value=10
}
return item;
}));
if you already know the index :
let users=response.data.user;
if(users[0].name == "John") {
users[0].value = 10
}
commit("SET_USER", users);
Upvotes: 1