import { loginUser } from "@/service/user.service"; export default { // 自带命名空间 namespaced: true, state: { // 用户账号密码 userInfo: { name: null, password: null, }, }, getters: { userInfo: (state) => { return state.userInfo; }, }, mutations: { // 配置用户登录信息 userInfo setUserInfo(state, userInfo) { state.userInfo = userInfo; }, }, actions: { // Promise loginUserInfo({ commit }, info) { console.log("登录认证 store里面", "info", info); return new Promise(async (resolve, reject) => { try { let data = await loginUser(info); // 等待登录信息 console.log("返回的post", data); // 调用 mutation commit("setUserInfo", info); resolve(data); } catch (error) { reject(error); } }); }, }, };