F
F
fierfoxik2018-07-14 22:09:25
JavaScript
fierfoxik, 2018-07-14 22:09:25

How to call a function in a component after a property in the vuex store changes?

I have a datastore in vuex and two components.
The first component is a range slider where I change the slider values ​​and immediately send them to the store.
The second is the component in which I need to call my function when the store changes .
my store

state: {
    value: 0,
      rgbColors: {
        red: 0
      }
  },

As I understand it, I need to use store.subscribe.watch.rgbColors.red or store.watch.rgbColors.red right?
And if so, how to use it and call the function when the value changes?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Nagorny, 2018-07-14
@fierfoxik

Through watch
You can shove gettersin computed
And get it

const app = new Vue({
    store,
    el: '#app',
    data() {
        return {}
    },
    computed: {
        rgbColors() {
            return this.$store.getters.rgbColors
        }
    },
    watch: {
        rgbColors(newValue, oldValue) {

        }
    }
});

And here is the link

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question