hx/store/user.ts

35 lines
671 B
TypeScript
Raw Permalink Normal View History

2024-10-18 18:09:15 +08:00
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
const initState = { nickname: '', avatar: '' }
export const useUserStore = defineStore(
'user',
() => {
const userInfo = ref<IUserInfo>({ ...initState })
const setUserInfo = (val: IUserInfo) => {
userInfo.value = val
}
const clearUserInfo = () => {
userInfo.value = { ...initState }
}
const reset = () => {
userInfo.value = { ...initState }
}
const isLogined = computed(() => !!userInfo.value.token)
return {
userInfo,
setUserInfo,
clearUserInfo,
isLogined,
reset,
}
},
{
persist: true,
},
)