import { ref, Ref } from '@vue/composition-api'; import api from '@/api'; import { Role } from '@/types'; let roles: Ref | null = null; let loading: Ref | null = null; export default function useNavigation(): Record { if (roles === null) { roles = ref(null); } if (loading === null) { loading = ref(false); } if (roles.value === null && loading?.value === false) { fetchRoles(); } return { roles, loading }; async function fetchRoles() { if (!loading || !roles) return; loading.value = true; const rolesResponse = await api.get(`/roles`, { params: { sort: 'name', }, }); roles.value = rolesResponse.data.data; loading.value = false; } }