Jan 9, 2020 in Vue.JS

When would you use the keep-alive element?

1 Answer

0 votes
Jan 9, 2020

When we dynamically switch components as a result of a data property or some other reactive state, they’re re-rendered everytime they’re toggled in to render. While you may want this behaviour, there are situations where re-rendering may not be suitable. For instance, you may have a component that brings in data from an API call when created. You may not want to place this API call every time this component is dynamically switched in to render. That is when you can enclose the component within the keep-alive element. The keep-alive element caches the component and fetches it from there instead of re-rendering it every time.

Related questions

0 votes
Feb 4, 2020 in Vue.JS
  • #vuejs-elements
0 votes
Mar 12, 2020 in C Plus Plus
0 votes
Nov 26, 2019 in React JS