Answer the question
In order to leave comments, you need to log in
How to update value in store?
The quantity counter component is used in several other components. It is necessary that when the quantity in one component changes, it changes in all. To do this, I use Vuex, I get the initial amount (0), but I can’t change it. I tried to equate to the local quantity in the component and send it, but somehow it did not work out.
<template>
<div class="buttons" :class="{'visible': count > 0}">
<button class="minus" @click="count > 0 ? count-- : count">-</button>
<p class="count">
<span>✖</span>
{{count}}
</p>
<button class="plus" @click="count++">+</button>
</div>
</template>
<script>
export default {
props: ["index"],
data() {
return {
};
},
methods: {},
computed: {
count: {
get() {
return this.$store.getters.getDishes[this.index].count
},
set() {
this.$store.commit('setCount', {
count: this.localCount,
index: this.index
})
}
}
},
};
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