Version
"vuex": "^4.1.0"
Describe the bug
After registering the module dynamically, devtool shows that the state and getters are recomputed, but the getter-related views are not updated.
Reproduction
`
/* /src/store/index.ts */
import { createStore } from "vuex";
export const store = createStore({
state() {
return {
count: 0
}
},
getters: {
double(state) {
return state.count * 2;
}
},
mutations: {
increment(state, num) {
state.count += num;
},
decrement(state, num) {
state.count -= num;
}
}
});
`
`
/* /src/main.ts */
import { createApp } from 'vue';
import App from './App.vue';
import { store } from './store';
createApp(App).use(store).mount('#app');
`
`
/* /src/App.vue */
<script setup lang="ts">
import { computed } from '@vue/reactivity';
import { useStore } from 'vuex';
const store = useStore();
const count = computed(() => {
return store.state.count;
});
const double = computed(() => {
return store.getters.double;
});
function increment() {
store.commit('increment', 1);
}
function decrement() {
store.commit('decrement', 1);
}
function registerModule(name: string) {
const module = {
state() {
return {}
}
};
store.registerModule(name, module);
}
</script>
-
count: {{ count }} => double: {{ double }}
+
register module
`
Expected behavior
The view associated with the getter should be updated.
Additional context
No response
Validations
Version
"vuex": "^4.1.0"
Describe the bug
After registering the module dynamically, devtool shows that the state and getters are recomputed, but the getter-related views are not updated.
Reproduction
`
/* /src/store/index.ts */
import { createStore } from "vuex";
export const store = createStore({
state() {
return {
count: 0
}
},
getters: {
double(state) {
return state.count * 2;
}
},
mutations: {
increment(state, num) {
state.count += num;
},
decrement(state, num) {
state.count -= num;
}
}
});
`
`
/* /src/main.ts */
import { createApp } from 'vue';
import App from './App.vue';
import { store } from './store';
createApp(App).use(store).mount('#app');
`
`
<script setup lang="ts"> import { computed } from '@vue/reactivity'; import { useStore } from 'vuex'; const store = useStore(); const count = computed(() => { return store.state.count; }); const double = computed(() => { return store.getters.double; }); function increment() { store.commit('increment', 1); } function decrement() { store.commit('decrement', 1); } function registerModule(name: string) { const module = { state() { return {} } }; store.registerModule(name, module); } </script>/* /src/App.vue */
- count: {{ count }} => double: {{ double }} +
register module
`Expected behavior
The view associated with the getter should be updated.
Additional context
No response
Validations