D
D
dimakal12019-09-16 18:26:26
Vue.js
dimakal1, 2019-09-16 18:26:26

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>&#10006;</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

1 answer(s)
0
0xD34F, 2019-09-16
@dimakal1

set(count) {
  this.$store.commit('setCount', {
    count,
    index: this.index,
  });
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question