Composables

A composable is a function that encapsulates and reuses stateful logic using Vue's Composition API (ref, computed, hooks). By convention, its name starts with use. It returns the data and functions useful to the component, which avoids duplication.

Example

export function useCompteur() {
  const n = ref(0)
  const inc = () => n.value++
  return { n, inc }
}

Related concepts

The whole glossary