Blame view

src/store/store.js 1.31 KB
03dcbf0c1   Neeraj Sharma   fix all api and r...
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   Neeraj Sharma   implement school ...
8
9
10
      strict: true,
      plugins: [
          createPersistedState()
03dcbf0c1   Neeraj Sharma   fix all api and r...
11
12
13
14
15
      ],
      state: {
          token: null,
          data: null,
          isUserLoggedIn: false,
e3e2a04c6   Neeraj Sharma   first commit
16
          id: null,
37150e7c1   Neeraj Sharma   implement school ...
17
          role: null
03dcbf0c1   Neeraj Sharma   fix all api and r...
18
19
20
      },
      // serve as the one and only way to change the state of the data in the state object
      mutations: {
37150e7c1   Neeraj Sharma   implement school ...
21
          setToken(state, token) {
03dcbf0c1   Neeraj Sharma   fix all api and r...
22
              state.token = token
37150e7c1   Neeraj Sharma   implement school ...
23
24
25
26
27
28
                  //state.isUserLoggedIn = !!(token)
              if (token != null) {
                  state.isUserLoggedIn = true
              } else {
                  state.isUserLoggedIn = false
              }
03dcbf0c1   Neeraj Sharma   fix all api and r...
29
          },
37150e7c1   Neeraj Sharma   implement school ...
30
          setUser(state, data) {
03dcbf0c1   Neeraj Sharma   fix all api and r...
31
32
              state.data = data
          },
37150e7c1   Neeraj Sharma   implement school ...
33
34
          Id(state, id) {
              state.id = id
03dcbf0c1   Neeraj Sharma   fix all api and r...
35
          },
37150e7c1   Neeraj Sharma   implement school ...
36
37
38
39
          Role(state, role) {
              state.role = role
          }
      },
03dcbf0c1   Neeraj Sharma   fix all api and r...
40
41
      //Action methods are referred to as being "dispatched"
      actions: {
37150e7c1   Neeraj Sharma   implement school ...
42
          setToken({ commit }, token) {
03dcbf0c1   Neeraj Sharma   fix all api and r...
43
44
              commit('setToken', token)
          },
37150e7c1   Neeraj Sharma   implement school ...
45
          setUser({ commit }, data) {
03dcbf0c1   Neeraj Sharma   fix all api and r...
46
47
              commit('setUser', data)
          },
37150e7c1   Neeraj Sharma   implement school ...
48
          Id({ commit }, id) {
e3e2a04c6   Neeraj Sharma   first commit
49
              commit('Id', id)
37150e7c1   Neeraj Sharma   implement school ...
50
51
52
          },
          Role({ commit }, role) {
              commit('Role', role)
eba96ec51   Neeraj Sharma   set login name on...
53
          }
03dcbf0c1   Neeraj Sharma   fix all api and r...
54
55
  
      }
37150e7c1   Neeraj Sharma   implement school ...
56

03dcbf0c1   Neeraj Sharma   fix all api and r...
57
  })