import { defineStore } from 'pinia' import { ref, computed } from 'vue' const initState = { nickname: '', avatar: '' } export const useUserStore = defineStore( 'user', () => { const userInfo = ref({ ...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, }, )