// store/user.js const state = { userInfo: null, token:uni.getStorageSync('token') || null, }; const mutations = { SET_USER_INFO(state, info) { state.userInfo = info; }, SET_TOKEN(state, token) { state.token = token; }, LOGOUT(state) { state.userInfo = null; state.token = null; }, }; const actions = { setUserInfo({ commit }, info) { commit("SET_USER_INFO", info); }, setToken({ commit }, token) { commit("SET_TOKEN", token); uni.setStorageSync('token', token); }, logout({ commit }) { commit("LOGOUT"); uni.removeStorageSync('token'); uni.removeStorageSync('userInfo'); }, }; export default { namespaced: true, state, mutations, actions, };