Answer the question
In order to leave comments, you need to log in
Vuex, authorization. Why do getters return undefined?
I'm trying to make authorization on Vue.js.
There is a registration method. He works fine.
registration ({commit}, data) {
return new Promise((resolve, reject) => {
axios
.post(localStorage.getItem('url') + 'user/add', data)
.then(response => {
const token = response.data.result.token
console.log(token)
localStorage.setItem('token', token)
axios.defaults.headers.common['Authorization'] = token
commit('AUTH_SUCCESS', token)
resolve(response)
})
.catch(err => {
commit('auth_error', err)
localStorage.removeItem('token')
reject(err)
})
})
},
AUTH_SUCCESS (state, token) {
state.status = 'success'
state.token = token
},
const getters = {
isLoggedIn: state => !!state.token,
authStatus: state => state.status
}
console.log(store.getters.isLoggedIn)
is already undefined. console.log(store.getters.authStatus)
- also Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question