Answer the question
In order to leave comments, you need to log in
Why is the state not saved after page reload or are there other options?
Good evening!
I continue to develop a site on vuejs. Previously I used localstorage to store some data (user data, authentication state, etc.), and now I decided to switch to vuex. Having studied the documentation a little, I decided to write a small functionality for authorization.
According to the idea, after the user is authorized, we write the data that the user is authorized to "state" - true. The change in vuex works i.e. in the debug console, this value is displayed normally - true. But after reloading the page, this value disappears - it becomes false.
I have 2 assumptions:
1. I'm doing something wrong
2. I'm not well acquainted with Vuex, and without understanding the essence of the technology, I began to work on it. Those. vuex only stores data without refreshing pages.
Here is the code :
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export const Auth = new Vuex.Store({
state: {
isAuth: false
},
mutations: {
authentificatedState(state) {
state.isAuth = true
},
// logout() {
// state.isAuth = false
// }
}
})
export default Auth
Answer the question
In order to leave comments, you need to log in
I have 2 assumptions:
1. I'm doing something wrong
2. I'm not familiar with Vuex...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question