import { ref, Ref, computed, ComputedRef } from 'vue'; interface User { id: number; username: string; nickname: string; } interface useState { getUser: () => ComputedRef; setUser: (data: User) => void; getRoles: () => ComputedRef; setRoles: (data: string[]) => void; } const user: Ref = ref({ id: 0, username: '', nickname: '', }); const roles: Ref = ref([]); export function useState(): useState { function getUser(): ComputedRef { return computed(() => { return { id: user.value.id, username: user.value.username, nickname: user.value.nickname, }; }); } function setUser(data: User): void { user.value = { id: data.id, username: data.username, nickname: data.nickname, }; } function getRoles(): ComputedRef { return computed(() => { return roles.value; }); } function setRoles(data: string[]): void { roles.value = data; } return { getUser, setUser, getRoles, setRoles, }; }