32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { defineStore } from "pinia";
|
||
import myAxios from '../api/myAxios'
|
||
|
||
export const userStore = defineStore( 'user' , {
|
||
//state是应用的核心数据,通常用于管理用户信息、应用设置、数据列表等。
|
||
state: () => {
|
||
return {
|
||
loginUser: {
|
||
id: 0,
|
||
phone: '',
|
||
userAvatar: '',
|
||
userName: '未登录',
|
||
userRole: 'notLogin'
|
||
}
|
||
}
|
||
}, persist: true,
|
||
//actions是用于定义和处理状态更改的方法。它们可以包含任意的逻辑,如异步请求、数据处理和状态更新。
|
||
actions: {
|
||
//获取登录用户信息
|
||
async getLoginUser(res:any) {
|
||
//请求登录信息
|
||
// const res = await myAxios.get('/user/get')
|
||
this.updateUser( res )
|
||
},
|
||
//更新用户信息
|
||
//更新state
|
||
updateUser(payLoad : any) {
|
||
this.loginUser = payLoad
|
||
console.log(payLoad,2654615165)
|
||
}
|
||
}
|
||
}) |