0

I had been using electron-vue and I met a few problems when I tried to share a set of global vars through electron and vue. I have tried vuex and i found that changes made in the main process(electron) doesn't appear in chrome process (values are different). I have also tried electron-vue but it cant trigger vue's update.

Yuxuan Lu
  • 316
  • 4
  • 13

1 Answers1

0

I just use electron (in devdependencies) and vue, vuex (in dependencies). No code is needed in the main Electron JS file (your main.js or app.js). I do like this :

index.html (main window) :

<script src="js/index.js"></script>

index.js :

const Vuex = require('vuex');

const store = new Vuex.Store({
    state: {
        // your global variables
        var1: 'test',
        var2: true
        },
    mutations: {
        setVar(state, data) {
            state[data.mykey] = data.val;
            } // setpref
        } // mutations
    }); // store

in any other renderer js or component :

// no require needed except vue.js done in html

computed: {
    // Variable got from the global store
    var1: function () { 
        return this.$store.state.var1; 
        }
    },

methods: {
    foo: function () {
        // changing global store variable
        this.$store.commit('setVar', {mykey: 'var1', val: 'test2'});
        },
JeffProd
  • 3,088
  • 1
  • 19
  • 38