Vuex - 如何检查模块是否已注册

Vuex - How to check if a module has been registered

当尝试使用 this.$store.unregisterModule([ModulePath, ModuleName]) 注销模块时,有时我会收到此警告控制台 [vuex] trying to unregister module 'ModulePath\ModuleName', which is not registered

我想知道是否有办法检查特定模块是否已注册?所以我可以像这样有条件地取消注册:

if(module ModuleName is registered) {
   this.$store.unregisterModule([ModulePath, ModuleName])
} 

您可以通过调用 store.hasModule 来完成。 来自 Vuex 文档:

Note that you may check if the module is already registered to the store or not via store.hasModule(moduleName) method.

Dynamic module registration