123456789101112131415161718192021222324252627282930313233 |
- //引入vue和vuex
- import Vue from 'vue'
- import Vuex from 'vuex'
- Vue.use(Vuex)
- const store = new Vuex.Store({ //全局变量定义
- state: {
- forcedLogin: false, //是否需要强制登录
- userLoginFlag: false, //用户是否登录
- userinfo:{}, //存放用户账号数据
- },
- mutations: {
- // 登录
- login(state, provider) {
- state.userLoginFlag = true;
- state.userInfo = provider
- uni.setStorage({ // 异步缓存用户信息
- key: "userinfo",
- data: provider
- })
- console.log(state.userInfo)
- },
- // 退出
- logout(state) {
- state.userLoginFlag = false;
- state.userInfo = {};
- uni.removeStorage({ // 清除用户信息
- key: "userinfo"
- })
- }
- }
- })
- export default store
|