Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state return previous data after page refresh #35

Open
larbijirari opened this issue Apr 24, 2019 · 5 comments
Open

state return previous data after page refresh #35

larbijirari opened this issue Apr 24, 2019 · 5 comments

Comments

@larbijirari
Copy link

larbijirari commented Apr 24, 2019

//store.js
import Vue from 'vue';
import Vuex from 'vuex';
import { createSharedMutations } from 'vuex-electron';
import AddresseStore from './Address.store';
Vue.use(Vuex);
export default new Vuex.Store({
  modules: {

    address: AddresseStore,
  },
  actions: {
    init() {},
  },
  plugins: [createSharedMutations()],
//   strict: process.env.NODE_ENV !== 'production',
});
//Address.store.js
export default{
state: {
    countryList:[],
},
getters:{
countryList(state){
return state.countryList
}
},
mutations:{
SET_COUNTRY_LIST(state,payload){

console.log(state.countryList);   
//------------PROBLEM---------------------
//=>first load: [] 
//=>after refresh page ['ITALY','SPAIN']  (don't want this behavior i want my state initial value which is []  because i'm reloading page)
//------------------------------------------------
state.countryList =payload;
}
},
actions:{
loadCountryList(context){
axios.get('localhost:3000/country-list').then((result)=>{
context.dispatch('SET_COUNTRY_LIST',result);
})
}
}
}
//address.component.vue
<template>
<section>
<div v-for="(country, index) in countryList" v-bind:key="index">
{{country}}
</div>
</section>
</template>
<script>
export default {
  name: 'AddressComponenet',
computed:{
countryList(){
return this.$store.getters['address/countryList'];
}
},
mounted(){
this.$store.dispatch('address/loadCountryList');
}
}
</script>

after page refresh store giveback previous data stored.
how can i prevent store from keeping data?

@NoelDavies
Copy link

Don't persist it, comment out plugins: [createSharedMutations()],

@larbijirari
Copy link
Author

larbijirari commented Apr 26, 2019

@NoelDavies thanks for your reply.
we relay on plugins: [createSharedMutations()] to allow axios authenticate using certificate from the main process, once we comment plugins: [createSharedMutations()] our request for example axios.get(...) won't work because it's executed from the renderer process because it doesn't support certificate authentication.

@akodkod
Copy link
Contributor

akodkod commented Aug 29, 2019

#44

@NoelDavies
Copy link

@larbijirari Your main process should essentially be a router / event handler, it shouldn't be doing anything chunky. I'd suggest finding another way to get your authentication to work and possibly creating a hidden/fake window to handle these tasks and offload them from your primary renderer's processing power for painting etc.

@crwgregory
Copy link

crwgregory commented Apr 20, 2021

You can delete the file that is saved manually.
Underneath the hood this module is using electron-store that writes a json file to app.getPath('userData');
https://github.com/vue-electron/vuex-electron/blob/master/src/persisted-state.js
https://www.npmjs.com/package/electron-store/v/2.0.0

So in your main process check to see where that is on your file system:

console.log('userData', app.getPath('userData'));

Then cd into the directory and remove the vuex.json file.


It would be cool if the plugin exposed a method that let us clear the saved state (basic CRUD). But I susspect you can instantiate your own Store and load it with the same name then call the .clear() method on it to clear the state manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants