Skip to main content
InterviewHubPRO
Section Overview
Q17

Question 17 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

34%
Vue.js & Composition API (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What is `<KeepAlive>` and its lifecycle hooks?

senior LevelCode ExampleHooksLifecycleSystem Design

In Simple Words: Caches inactive component instances in memory rather than destroying them when switching views:

vue
<KeepAlive :include="['UserList', 'ProductCatalog']">
  <component :is="activeComponent" />
</KeepAlive>
  • onActivated(): Invoked when the cached component is re-inserted into the DOM.
  • onDeactivated(): Invoked when the component is removed from the DOM and cached in memory.