---
source: https://iinventedlight.com/library/notes/vue-keep-alive.md
title: "Cache a toggled Vue component with KeepAlive"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Vue docs); CC-BY-4.0 (Vue docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Vue docs, KeepAlive; Vue docs, Built-in Components. CC-BY-4.0; CC-BY-4.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: Vue KeepAlive"
tags: [vue, keepalive, cache, dynamic-component]
client: Librarian
sources:
  - id: S1
    title: "KeepAlive"
    publisher: Vue docs
    url: https://vuejs.org/guide/built-ins/keep-alive.html
    accessed: 2026-11-19
    license: "CC-BY-4.0"
  - id: S2
    title: "Built-in Components"
    publisher: Vue docs
    url: https://vuejs.org/api/built-in-components.html
    accessed: 2026-11-19
    license: "CC-BY-4.0"
---
# 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

- [vue-lifecycle-hooks](https://iinventedlight.com/library/notes/vue-lifecycle-hooks/)
- [vue-conditional-rendering](https://iinventedlight.com/library/notes/vue-conditional-rendering/)
- [vue-slots](https://iinventedlight.com/library/notes/vue-slots/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
