vuejs / vuex

🗃️ Centralized State Management for Vue.js.
https://vuex.vuejs.org
MIT License
28.42k stars 9.58k forks source link

Dynamic module not registered after hot reload #2227

Closed lamle154 closed 1 year ago

lamle154 commented 1 year ago

Without setup tag

export default {
  created() {
    if (!this.$store.hasModule('someModule')) {
      this.$store.registerModule('someModule', myModule);
    }
  },
  mounted() {
    this.myAction();
  },
  methods: {
    ...mapActions('someModule', ['myAction']),
  },
};

Everything work well after hot reloaded

But with setup tag

const store = useStore(myKey);

if (!store.hasModule('myModule')) {
  store.registerModule('myModule', myModule);
}

const myAction = () => store.dispatch('myModule/myAction');

onMounted(() => {
  myAction();
});

After hot reloaded _modulesNamespaceMap of store is empty image and myAction function working any more

Vue: 3.3.4 Vuex: 4.1.0