← All notes

Vue composables reuse stateful logic with the Composition API

Answer: In Vue, a composable is a function that uses the Composition API to encapsulate and reuse stateful logic — state that changes over time, not a stateless formatter.

Side effects

A composable may perform side effects such as adding DOM event listeners or fetching data. The guide's rule is to register those in post-mount hooks such as onMounted() (especially under SSR) and to clean them up in onUnmounted().

Why setup() matters

Those hooks are lifecycle injection APIs. onMounted is created with createHook from the MOUNTED hook. onUnmounted is created with createHook from the UNMOUNTED hook. Lifecycle injection APIs can only be used during execution of setup(). Call a composable during setup() so those hooks can be registered.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: Vue.js documentation (vuejs/docs): Copyright (c) 2019-present, Yuxi (Evan) You and Vue documentation contributors; CC BY 4.0, text only (https://raw.githubusercontent.com/vuejs/docs/main/LICENSE). Vue.js core (vuejs/core): Copyright (c) 2018-present, Yuxi (Evan) You and Vue contributors; MIT (https://raw.githubusercontent.com/vuejs/core/main/LICENSE). Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Vue.js docs, Composables, CC BY 4.0, text only (vuejs/docs); Vue.js core, runtime-core apiLifecycle, MIT (vuejs/core). Notices: Vue.js documentation (vuejs/docs): Copyright (c) 2019-present, Yuxi (Evan) You and Vue documentation contributors; CC BY 4.0, text only (https://raw.githubusercontent.com/vuejs/docs/main/LICENSE). Vue.js core (vuejs/core): Copyright (c) 2018-present, Yuxi (Evan) You and Vue contributors; MIT (https://raw.githubusercontent.com/vuejs/core/main/LICENSE).

Cite this

Permanent ID: iil:note:as22a4he

iinventedlight. 2026. "Vue composables reuse stateful logic with the Composition API." iinventedlight Library, iil:note:as22a4he, version of 2026-11-10. https://iinventedlight.com/library/notes/vue-composables/. License: CC-BY-4.0.

@misc{iil_note_as22a4he,
  author = {{iinventedlight}},
  title = {{Vue composables reuse stateful logic with the Composition API}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-10},
  url = {https://iinventedlight.com/library/notes/vue-composables/},
  note = {Permanent ID iil:note:as22a4he. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/vue-composables.md.