Home » vue » this.$state.commit loses value after page refresh

this.$state.commit loses value after page refresh

Posted by: admin November 26, 2021 Leave a comment

Questions:

I have this code:

beforeCreate() {
    // Hide merchant switcher on this page
    this.$store.commit('SET_SHOW_MERCHANT_SWITCHER', false);
  },

This hides switcher on page, if set false. But after page refresh switcher comes back. So, I guess, this value becomes true. Is there a way to prevent this?

Answers:

The only way not to lose the value of a variable in front side is either you hard code the value or you use localstorage which saves a variable with a value in the browser and this is stored only in the browser of the device that user used. Otherwise, you need a database to store the value and fetch it everytime.