jiangchengfeiyi-Web/src/store/userStore.ts

32 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}
}
})