31 lines
779 B
TypeScript
31 lines
779 B
TypeScript
|
import { log } from 'console';
|
||
|
import { defineStore } from 'pinia'
|
||
|
import myAxios from "../API/myAxios";
|
||
|
|
||
|
export const userStore = defineStore('user', {
|
||
|
state: () => {
|
||
|
return {
|
||
|
loginUser:{
|
||
|
id:'',
|
||
|
username:'未登录',
|
||
|
avatarUrl:'',
|
||
|
userRole:'notLogin'
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
actions:{
|
||
|
//获取用户信息
|
||
|
// userStore.ts
|
||
|
async getLoginUser() {
|
||
|
const res: any = await myAxios.get('login/alipay');
|
||
|
if (res.code === 0 && res.data) {
|
||
|
this.loginUser = res.data; // 确保这里更新了loginUser对象
|
||
|
}
|
||
|
},
|
||
|
//更新用户信息
|
||
|
updateUser(payLoad: any) {
|
||
|
this.loginUser = payLoad;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
})
|