Blame view
src/store/store.js
1.51 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, |
99cd79184
|
17 18 |
role: null, schoolId: null |
03dcbf0c1
|
19 20 21 |
}, // serve as the one and only way to change the state of the data in the state object mutations: { |
37150e7c1
|
22 |
setToken(state, token) { |
03dcbf0c1
|
23 |
state.token = token |
37150e7c1
|
24 25 26 27 28 29 |
//state.isUserLoggedIn = !!(token) if (token != null) { state.isUserLoggedIn = true } else { state.isUserLoggedIn = false } |
03dcbf0c1
|
30 |
}, |
37150e7c1
|
31 |
setUser(state, data) { |
03dcbf0c1
|
32 33 |
state.data = data }, |
37150e7c1
|
34 35 |
Id(state, id) { state.id = id |
03dcbf0c1
|
36 |
}, |
37150e7c1
|
37 38 |
Role(state, role) { state.role = role |
99cd79184
|
39 40 41 |
}, SchoolId(state, schoolId) { state.schoolId = schoolId |
37150e7c1
|
42 43 |
} }, |
03dcbf0c1
|
44 45 |
//Action methods are referred to as being "dispatched" actions: { |
37150e7c1
|
46 |
setToken({ commit }, token) { |
03dcbf0c1
|
47 48 |
commit('setToken', token) }, |
37150e7c1
|
49 |
setUser({ commit }, data) { |
03dcbf0c1
|
50 51 |
commit('setUser', data) }, |
37150e7c1
|
52 |
Id({ commit }, id) { |
e3e2a04c6
|
53 |
commit('Id', id) |
37150e7c1
|
54 55 56 |
}, Role({ commit }, role) { commit('Role', role) |
99cd79184
|
57 58 59 |
}, SchoolId({ commit }, schoolId) { commit('SchoolId', schoolId) |
eba96ec51
|
60 |
} |
03dcbf0c1
|
61 62 |
} |
37150e7c1
|
63 |
|
03dcbf0c1
|
64 |
}) |