上传代码
This commit is contained in:
32
CampusExpressDelivery/src/store/userStore.ts
Normal file
32
CampusExpressDelivery/src/store/userStore.ts
Normal file
@ -0,0 +1,32 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user