I have this store in Vue App using vuex :
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
email: null,
token: localStorage.getItem('token') || null,
role: null
},
mutations: {
saveToken (state, token) {
state.token = token
}
},
actions: {
createToken (context, user) {
axios.post('http://127.0.0.1:8001/api/user/login', {
email: user.email,
password: user.password
}).then(response => {
const token = response.data.token
localStorage.setItem('token', token)
context.commit('saveToken', token)
})
}
},
modules: {
}
})
When I login the token state is changed correctly, but when I refresh the page the state is null again.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…