Trung BìnhVue.js iconVue.js

KeepAlive component là gì?

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

Xem toàn bộ Vue.js cùng filter theo level & chủ đề con.

Mở danh sách Vue.js