File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 11import Vue from 'vue' ;
22import Vuex from 'vuex' ;
3+ import createPersistedState from 'vuex-persistedstate' ;
4+ import SecureLS from 'secure-ls' ;
5+ import user from './modules/user' ;
6+
7+ const ls = new SecureLS ( { isCompression : false } ) ;
38
49Vue . use ( Vuex ) ;
510
611export default new Vuex . Store ( {
12+ strict : true ,
713 state : {
814 } ,
915 mutations : {
1016 } ,
1117 actions : {
1218 } ,
1319 modules : {
20+ user,
1421 } ,
22+ plugins : [
23+ createPersistedState ( {
24+ paths : [ 'user' ] ,
25+ storage : {
26+ getItem : ( key ) => ls . get ( key ) ,
27+ setItem : ( key , value ) => ls . set ( key , value ) ,
28+ removeItem : ( key ) => ls . remove ( key ) ,
29+ } ,
30+ } ) ,
31+ ] ,
1532} ) ;
Original file line number Diff line number Diff line change 1+ /* eslint-disable no-shadow */
2+
3+ const state = {
4+ user : null ,
5+ } ;
6+
7+ const getters = {
8+ getLoggedInUser ( state ) {
9+ return state . user ;
10+ } ,
11+ } ;
12+
13+ const mutations = {
14+ login ( state , user ) {
15+ state . user = user ;
16+ } ,
17+ logout ( state ) {
18+ state . user = null ;
19+ } ,
20+ } ;
21+
22+ const actions = {
23+ login ( state , user ) {
24+ state . commit ( 'login' , user ) ;
25+ } ,
26+ logout ( state ) {
27+ state . commit ( 'logout' ) ;
28+ } ,
29+ } ;
30+
31+ export default {
32+ state,
33+ getters,
34+ mutations,
35+ actions,
36+ } ;
You can’t perform that action at this time.
0 commit comments