<KeepAlive> cache component instance khi unmount — state được giữ nguyên khi switch lại:
vue
<KeepAlive :include="['FormStep1', 'FormStep2']" :max="5">
<component :is="currentTab" />
</KeepAlive>- Lifecycle hooks cho cached components:
onActivated(khi cache hit, component show lại),onDeactivated(khi bị hide, không unmount). - Dùng cho: tab views, multi-step forms, expensive components cần giữ state.
Pitfall: cached components vẫn chiếm bộ nhớ — dùng :max để limit, tránh cache tất cả.