user.js 1.0 KB
Newer Older
yma16's avatar
yma16 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import { loginUser } from "@/service/user.service";
export default {
    // 自带命名空间
    namespaced: true,
    state: {
        // 用户账号密码
        userInfo: 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", data);
                    resolve(data);
                } catch (error) {
                    reject(error);
                }
            })
        }
    }
}