Skip to content

Instantly share code, notes, and snippets.

@DezChuang
Created January 15, 2019 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DezChuang/3d6a049d960fa9f893893a71004ffaa2 to your computer and use it in GitHub Desktop.
Save DezChuang/3d6a049d960fa9f893893a71004ffaa2 to your computer and use it in GitHub Desktop.
/plugins/register-store.js
function registerStore({ module, moduleName, store }) {
const moduleIsRegistered =
store._modules.root._children[moduleName] !== undefined
const stateExists = store.state[moduleName]
if (!moduleIsRegistered) {
store.registerModule(moduleName, module, { preserveState: stateExists })
}
}
export default ({ app }, inject) => {
inject('registerStore', registerStore)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment