index.js
857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
userData: {},
hasLogin: false
},
mutations: {
login(state, provider) {
state.hasLogin = true;
state.userData = provider;
//缓存用户登陆状态
uni.setStorageSync('userData', provider)
},
logout(state) {
state.hasLogin = false;
state.userData = {};
uni.removeStorageSync('userData');
uni.removeStorageSync('historyUser');
},
historyUser(state, provider) {
//缓存为历史登录用户
uni.setStorageSync('historyUser', provider);
}
},
actions: {
setUserData: function(context, obj) {
context.commit('login', obj)
},
logout: function(context) {
context.commit('logout')
},
setHistoryUser: function(context, obj) {
context.commit('historyUser', obj)
}
}
})
export default store