[Vuejs]-Vuex data just show once then won't display after reloading

0👍

I don’t see anywhere that you “persist” the fetched data. Vuex does not persist the data across reloads, it acts as an in-memory storage

You still have to persist your data to local storage of some sorts like localStorage or indexedDB.

Here is a simple solution:

const store = {
    careers: JSON.parse(localStorage.getItem('careers') || '[]');
};

const mutations = {
  RETRIEVE_CAREERS: (state, career) => {
    state.careers = career;
    localStorage.setItem('careers', JSON.stringify(career));
  }
};

Leave a comment