Composition API je doporučený způsob psaní Vue 3 komponent. Lepší TypeScript podpora, reusable logika, jednodušší velké komponenty.
Script setup¶
{{ count }} ({{ doubled }})
Composables¶
// composables/useFetch.ts export function useFetch(url: string) { const data = ref(null); const error = ref(null); const loading = ref(true); fetch(url) .then(r => r.json()) .then(v => data.value = v) .catch(e => error.value = e) .finally(() => loading.value = false); return { data, error, loading }; } // Použití v komponentě const { data: users, loading } = useFetch(‘/api/users’);