Blame view
src/store/store.js
1.31 KB
03dcbf0c1
|
1 2 3 4 5 6 7 |
import Vue from 'vue' import Vuex from 'vuex' import createPersistedState from 'vuex-persistedstate' Vue.use(Vuex) export default new Vuex.Store({ |
37150e7c1
|
8 9 10 |
strict: true, plugins: [ createPersistedState() |
03dcbf0c1
|
11 12 13 14 15 |
], state: { token: null, data: null, isUserLoggedIn: false, |
e3e2a04c6
|
16 |
id: null, |
37150e7c1
|
17 |
role: null |
03dcbf0c1
|
18 19 20 |
}, // serve as the one and only way to change the state of the data in the state object mutations: { |
37150e7c1
|
21 |
setToken(state, token) { |
03dcbf0c1
|
22 |
state.token = token |
37150e7c1
|
23 24 25 26 27 28 |
//state.isUserLoggedIn = !!(token) if (token != null) { state.isUserLoggedIn = true } else { state.isUserLoggedIn = false } |
03dcbf0c1
|
29 |
}, |
37150e7c1
|
30 |
setUser(state, data) { |
03dcbf0c1
|
31 32 |
state.data = data }, |
37150e7c1
|
33 34 |
Id(state, id) { state.id = id |
03dcbf0c1
|
35 |
}, |
37150e7c1
|
36 37 38 39 |
Role(state, role) { state.role = role } }, |
03dcbf0c1
|
40 41 |
//Action methods are referred to as being "dispatched" actions: { |
37150e7c1
|
42 |
setToken({ commit }, token) { |
03dcbf0c1
|
43 44 |
commit('setToken', token) }, |
37150e7c1
|
45 |
setUser({ commit }, data) { |
03dcbf0c1
|
46 47 |
commit('setUser', data) }, |
37150e7c1
|
48 |
Id({ commit }, id) { |
e3e2a04c6
|
49 |
commit('Id', id) |
37150e7c1
|
50 51 52 |
}, Role({ commit }, role) { commit('Role', role) |
eba96ec51
|
53 |
} |
03dcbf0c1
|
54 55 |
} |
37150e7c1
|
56 |
|
03dcbf0c1
|
57 |
}) |