Get immutable data from vuex to render in component?
-
good afternoon!
such a question: I get one value from vuex.store, which is rendered in two different components,
but you need to make sure that when the lower number changes, when increasing / decreasing with the controller,
did the top one stay the same and didn't get rendered?
I get the value using a getter, and calculate it using computed methods
JavaScript Everett Kent, Oct 18, 2019 -
& lt; span v-once & gt; {{data}} & lt; / span & gt;
When data is changed, initial value .Ian Savage -
Instead of computed, make a regular component property, when creating an instance, copy the value from the store:
data() {
return {
value: this.$store.state.value,
};
},Anonymous -
you are referring to the same array / object. when you get it, use the spread operator '...' to get an absolutely new object / array and work with it.
for example you got your object, then write this.counter = {... object} or this.counter = [... array].
After that, changes to this.counter will not affect the data received from the storage in any way.
guideAnonymous
3 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!