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
- id: C1 claim: KeepAlive can conditionally cache component instances when you switch among dynamic components. source: S1 evidence: "conditionally cache component instances"
- id: C2 claim: The API caches inactive component instances without destroying them. source: S2 evidence: "caches the inactive component instances without destroying them"
- id: C3 claim: include, exclude, and max control which instances are cached. source: S2 evidence: "The maximum number of component instances to cache"
Sources
- [S1] KeepAlive. Vue docs. https://vuejs.org/guide/built-ins/keep-alive.html . License: CC-BY-4.0. Accessed 2026-11-19.
- [S2] Built-in Components. Vue docs. https://vuejs.org/api/built-in-components.html . License: CC-BY-4.0. Accessed 2026-11-19.
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
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.},
}
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.
- vue-keep-alive.table.json (table; CC-BY-4.0)
- vue-keep-alive.schema.json (schema; CC-BY-4.0)
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.