File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
import { createStore } from 'vuex';
export default createStore({
state: {
token: null,
userId: null,
authcd: null,
},
getters: {
isLoggedIn(state) {
return !!state.token;
},
getUserInfo(state) {
return {
userId: state.userId,
authcd: state.authcd,
};
}
},
mutations: {
setToken(state, token) {
state.token = token;
},
clearToken(state) {
state.token = null;
state.userId = null;
state.authcd = null;
},
setUser(state, userId) {
state.userId = userId;
},
setAuthcd(state, authcd) {
state.authcd = authcd;
}
},
actions: {
login({ commit }, token) {
commit('setToken', token);
localStorage.setItem('token', token);
},
logout({ commit }) {
commit('clearToken');
localStorage.removeItem('token');
},
}
});