Answer the question
In order to leave comments, you need to log in
Why doesn't the getter in Vuex update the component when it changes?
Why don't getters in Vuex update the component when they change? Everything is reactive.
store.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
count: 0
},
getters: {
doneTodos (state) {
return state.count + 5;
}
},
mutations: {
increment (state, { a }) {
state.count = a;
}
}
});
setTimeout(() => {
store.commit('increment', { a: 4 });
}, 2000);
export default store;
<template>
<div>
<div>{{ doneTodos }}</div>
</div>
</template>
<script>
import { mapState, mapGetters } from 'vuex'
export default {
data () {
return {
text: 'lorem...',
is: false,
y: '',
m: ''
}
},
computed: {
...mapState([
'count',
]),
...mapGetters([
'doneTodos'
])
}
}
</script>
Answer the question
In order to leave comments, you need to log in
And where did you get the idea that the update is not performed? Maybe the problem is not in the getters, but in you - are you not understanding something, or are you looking somewhere in the wrong place?
Tell us what you expect to see and what you actually see. And then in the code you showed, no problems associated with the update can be seen.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question