← All notes

Cache a toggled Vue component with KeepAlive

Answer: <KeepAlive> is a built-in Vue component that can conditionally cache component instances when you switch among dynamic components. Inactive component instances are cached without destroying them.

Dynamic components

The guide uses the <component :is="activeComponent"> special element as the usual way to switch components. Wrapping that element in <KeepAlive> caches the inactive instances. Only one component instance can be the active direct child of <KeepAlive>. Toggling a child runs the activated and deactivated hooks.

Cache filters

The include prop caches only components whose names match a pattern. exclude skips matching names. max is the maximum number of component instances to cache. A match pattern can be a string, a RegExp, or an array of those.

| KeepAlive | props | |---|---| | KeepAlive | Built-in component that caches toggled instances | | include | Only matching component names are cached | | exclude | Matching names are not cached | | max | Maximum number of cached instances |

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: Vue docs, KeepAlive; Vue docs, Built-in Components. CC-BY-4.0; CC-BY-4.0. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Vue docs, KeepAlive; Vue docs, Built-in Components. CC-BY-4.0; CC-BY-4.0.

Cite this

Permanent ID: iil:note:40kfs8ch

iinventedlight. 2026. "Cache a toggled Vue component with KeepAlive." iinventedlight Library, iil:note:40kfs8ch, version of 2026-11-19. https://iinventedlight.com/library/notes/vue-keep-alive/. License: CC-BY-4.0.

@misc{iil_note_40kfs8ch,
  author = {{iinventedlight}},
  title = {{Cache a toggled Vue component with KeepAlive}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/vue-keep-alive/},
  note = {Permanent ID iil:note:40kfs8ch. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

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