Blame view
src/store/store.js
2.65 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 |
role: null, |
68d742034
|
18 19 |
// schoolId: null, schoolToken: null, |
32fcd6960
|
20 21 22 23 24 25 26 |
schoolRole: null, studentsData: [], }, getters: { GET_STUDENTS_DATA: state => { return state.studentsData }, |
03dcbf0c1
|
27 28 29 |
}, // serve as the one and only way to change the state of the data in the state object mutations: { |
37150e7c1
|
30 |
setToken(state, token) { |
03dcbf0c1
|
31 |
state.token = token |
32fcd6960
|
32 |
//state.isUserLoggedIn = !!(token) |
37150e7c1
|
33 34 35 36 37 |
if (token != null) { state.isUserLoggedIn = true } else { state.isUserLoggedIn = false } |
03dcbf0c1
|
38 |
}, |
68d742034
|
39 40 |
setSchoolToken(state, schoolToken) { state.schoolToken = schoolToken |
32fcd6960
|
41 |
//state.isUserLoggedIn = !!(token) |
68d742034
|
42 43 44 45 46 47 |
if (schoolToken != null) { state.isSchoolLoggedIn = true } else { state.isSchoolLoggedIn = false } }, |
37150e7c1
|
48 |
setUser(state, data) { |
03dcbf0c1
|
49 50 |
state.data = data }, |
37150e7c1
|
51 52 |
Id(state, id) { state.id = id |
03dcbf0c1
|
53 |
}, |
37150e7c1
|
54 55 |
Role(state, role) { state.role = role |
99cd79184
|
56 |
}, |
68d742034
|
57 58 59 |
setSchoolRole(state, schoolRole) { state.schoolRole = schoolRole }, |
32fcd6960
|
60 61 62 |
SET_STUDENTS_DATA(state, data) { state.studentsData = data }, |
68d742034
|
63 64 65 |
// SchoolId(state, schoolId) { // state.schoolId = schoolId // } |
37150e7c1
|
66 |
}, |
03dcbf0c1
|
67 68 |
//Action methods are referred to as being "dispatched" actions: { |
32fcd6960
|
69 70 71 |
setToken({ commit }, token) { |
03dcbf0c1
|
72 73 |
commit('setToken', token) }, |
32fcd6960
|
74 75 76 |
setSchoolToken({ commit }, schoolToken) { |
68d742034
|
77 78 |
commit('setSchoolToken', schoolToken) }, |
32fcd6960
|
79 80 81 |
setUser({ commit }, data) { |
03dcbf0c1
|
82 83 |
commit('setUser', data) }, |
32fcd6960
|
84 85 86 87 88 89 90 91 |
SET_STUDENTS_DATA({ commit }, data) { commit('SET_STUDENTS_DATA', data) }, Id({ commit }, id) { |
e3e2a04c6
|
92 |
commit('Id', id) |
37150e7c1
|
93 |
}, |
32fcd6960
|
94 95 96 |
Role({ commit }, role) { |
37150e7c1
|
97 |
commit('Role', role) |
99cd79184
|
98 |
}, |
32fcd6960
|
99 100 101 |
setSchoolRole({ commit }, schoolRole) { |
68d742034
|
102 103 104 105 106 |
commit('setSchoolRole', schoolRole) }, // SchoolId({ commit }, schoolId) { // commit('SchoolId', schoolId) // } |
03dcbf0c1
|
107 108 |
} |
37150e7c1
|
109 |
|
03dcbf0c1
|
110 |
}) |