The easiest way to share your Vuex Store between all processes (including main).
โญ Persisted state
โญ Shared mutations
Installation of the Vuex Electron easy as 1-2-3.
-
Install package with using of yarn or npm:
yarn install vuex-electron
or
npm install vuex-electron
-
Include plugins in your Vuex store::
import Vue from "vue" import Vuex from "vuex" import { createPersistedState, createSharedMutations } from "vuex-electron" Vue.use(Vuex) export default new Vuex.Store({ // ... plugins: [ createPersistedState(), createSharedMutations() ], // ... })
-
In case if you enabled
createSharedMutations()
plugin you need to create an instance of store in the main process. To do it just add this line into your main process (for examplesrc/main.js
):import './path/to/your/store'
-
Well done you did it! The last step is to add the star to this repo ๐
Usage example: Vuex Electron Example
In renderer process to call actions you need to use dispatch
or mapActions
. Don't use commit
because actions fired via commit
will not be shared between processes.
[Deprecated] The whitelist and blacklist features do not work, and have been replaced by the ignoredPaths, ignoredCommits and invertIgnored options.
Available options for createPersistedState()
createPersistedState({
// Inverts the ignoredPaths and ignoredCommits settings
invertIgnored: true,
// Ignores specific paths on the state object, when persisting.
ignoredPaths: ["a.path.on.state", "another.path"],
// Specifies commits that will not trigger a persistance update.
ignoredCommits: ["increment"],
// or a variation using a function
ignoredCommits: (mutation) => {
return true // Return true for mutations that should not trigger an update
}
})
Andrew Emelianenko
IG: @truemelianenko