xiaokuaisong-Web/tencent/src/stores/userStore.ts
2024-10-18 16:01:37 +08:00

37 lines
1020 B
TypeScript

import { defineStore } from 'pinia'
import myAxios from "../API/myAxios.ts";
export const userStore = defineStore('user', {
state: () => {
return {
loginUser:{
username:'未登录',
avatarUrl:'',
userRole:'notLogin',
createTime:'null'
}
}
},
persist: true,
actions:{
//获取用户信息
async getLoginUser() {
//请求登录信息
console.log("login已经调用");
//const res:any = await myAxios.get('/user/current');
const res:any = await myAxios.get('/user/current', { withCredentials: true });
console.log("11111")
console.log(res);
console.log("11111222222")
if(res.code === 0 && res.data) {
this.updateUser(res.data)
}
},
//更新用户信息
updateUser(payLoad: any) {
this.loginUser = payLoad;
}
}
})