roose 4 years ago
parent
commit
469c6eaf3e
1 changed files with 31 additions and 0 deletions
  1. 31 0
      store/index.js

+ 31 - 0
store/index.js

@@ -0,0 +1,31 @@
+import Vue from 'vue';
+import Vuex from 'vuex'
+
+Vue.use(Vuex)
+
+const store = new Vuex.Store({  
+    state: {  
+        uerInfo: {},  
+        hasLogin: false  
+    },  
+    mutations: {  
+        login(state, provider) {//改变登录状态  
+            state.hasLogin = true  
+            state.uerInfo = provider  
+			console.log(provider)
+            uni.setStorage({//将用户信息保存在本地  
+                key: 'userInfo',  
+                data: provider  
+            })  
+        },  
+        logout(state) {//退出登录  
+            state.hasLogin = false  
+            state.uerInfo = {}  
+            uni.removeStorage({  
+                key: 'userInfo'  
+            })  
+        }  
+    }  
+})
+
+export default store