xiaokuaisong-xiaochengxu/uniapp04/stores/userStore.ts

31 lines
779 B
TypeScript
Raw Normal View History

2024-10-18 07:53:00 +00:00
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;
}
}
})