uniapp vuex 搭建

时间:2024-10-29 09:26:10
export default { namespaced: true, state: { token:"", //token userId:"", //用户id userName:"",//用户姓名 }, mutations: { SET_TOKEN(state,token){ state.token = token uni.setStorageSync("token",token) }, LOGIN_OUT(state){ state.token = "" uni.removeStorageSync("token") //uni.clearStorageSync() uni.reLaunch({ url:"/pages/index/index" }) }, SET_USERID(state,id){ state.userId = id uni.setStorageSync("userId",id) }, SET_USERNAME(state,name){ state.userName = name uni.setStorageSync("userName",name) }, }, actions: { setToken({commit},token){ commit("SET_TOKEN",token) }, setUserId({commit},id){ commit("SET_USERID",id) }, loginOut({commit}){ commit("LOGIN_OUT") }, } }