rubystarashe / nuxt-vuex-localstorage

MIT License
161 stars 18 forks source link

Data is deleted it when i refresh the page #24

Closed nirokun closed 4 years ago

nirokun commented 4 years ago

This is my localStorage.js ``# store/localStorage.js export const state = () => ({ logged: false, token: '', user: {} })

export const mutations = { loginAction (state, token) { console.log('login') state.user = token state.token = state.user.jti state.logged = true this.$router.push('/') console.log(state) },

logout (state) { console.log('logout') state.token = '' state.user = '' this.$router.push('/') } } ` and with this commnadthis.$store.commit('localStorage/loginAction', response.data)` i change the data. When ever i refresh the page the data reset to initial value.

jcorry commented 4 years ago

I'm seeing the same thing...

nirokun commented 4 years ago

Hey! I managed to fix this in my code. The problem wasn't the localStorage.js, the problem was when the data is charged. With the computed method in the tutorial i was able to use my data stored in localStorage.js. That's lead me to another question. When the data is avalible? Before created or while being created, or before mounted or while being mounted?