33 lines
877 B
TypeScript
33 lines
877 B
TypeScript
import {defineStore} from 'pinia'
|
|
import myAxios from "../api/myAxios";
|
|
|
|
export const userStore = defineStore('user', {
|
|
// 推荐使用 完整类型推断的箭头函数
|
|
state: () => {
|
|
return {
|
|
loginUser: {
|
|
username: '未登录',
|
|
avatarUrl: '',
|
|
userRole: 'notLogin',
|
|
phone:''
|
|
}
|
|
}
|
|
}, persist: true,
|
|
|
|
actions: {
|
|
// 获取登录用户信息
|
|
async getLoginUser() {
|
|
// 请求登录信息
|
|
const res: any = await myAxios.get('/user/current');
|
|
if (res.code === 0 && res.data) {
|
|
console.log("56765765756567")
|
|
this.updateUser(res.data)
|
|
}
|
|
},
|
|
// 更新用户信息
|
|
updateUser(payLoad: any) {
|
|
this.loginUser = payLoad;
|
|
}
|
|
}
|
|
})
|