35 lines
671 B
TypeScript
35 lines
671 B
TypeScript
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,
|
|
},
|
|
)
|