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 example src/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.
Available options for createPersistedState()
createPersistedState({
whitelist: ["whitelistedMutation", "anotherWhitelistedMutation"],
// or
whitelist: (mutation) => {
return true
},
// or
blacklist: ["ignoredMutation", "anotherIgnoredMutation"],
// or
blacklist: (mutation) => {
return true
}
})
Andrew Emelianenko
IG: @truemelianenko
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。