I have a situation where I want to persist only the user data in my store, which is stored in a nuxt.js store. Currently, all data in the store is being persisted in localStorage. Here is my implementation in store/login.js
.
export const state = () => ({
user: ''
})
export const mutations = {
setUser(state, newUser) {
state.user = newUser;
}
}
export const getters = {
getUser(state) {
return state.user
}
}
To achieve this, I am utilizing the vuex-persist
plugin for data persistence. Below is the setup in plugin/vuex-persist
:
import VuexPersistence from 'vuex-persist';
export default ({ store }) => {
new VuexPersistence({
key: 'vuex',
storage: window.localStorage,
}).plugin(store);
}
Your assistance on this matter is greatly appreciated!