Answer the question
In order to leave comments, you need to log in
How to mutate state correctly?
<list>
<item v-for="item in items" :item="item" :key="item.id">...</item>
</list>
items = [{
id: 1,
age: 24,
public: 0
}, {
id: 2,
age: 23,
public: 0
}, {
id: 3,
age: 52,
public: 1
}]
props: ['item'],
methods: {
updatePublic1() {
this.$store.commit('update:public1', this.item.id)
},
updatePublic2() {
this.$store.commit('update:public2', this.item)
}
}
'update:public1'(state, id) {
const item = state.items.find(el => el.id === id)
item.public = !item.public
}
'update:public2'(state, item) {
item.public = !item.public
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question