import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const store = new Vuex.Store({ state: { hasLogin: false, token:'', userInfo: {}, }, mutations: { setLogin(state, userInfo) { state.userInfo = userInfo || {} state.token = userInfo.accessToken state.tokenhead = userInfo.tokenhead state.hasLogin = Boolean(state.token) uni.setStorage({ key: "userInfo", data: userInfo.data }) uni.setStorage({ key: "hasLogin", data: true }) uni.setStorage({ key: "token", data: userInfo.accessToken }); uni.setStorage({ key: "tokenhead", data: userInfo.tokenhead }); }, logout(state) { userInfo = {} hasLogin: false, uni.removeStorage({ key: "userInfo" }) } }, actions: { } }) export default store