How to use keep-alive in vuejs?

1. We can achieve it by using

// Render component inside

special tag which has provided by vueJs.

2. use life cycle hooks:

a. activated()

b. deactivated()

The only disadvantage is that these components are kept in memory and therefore their state is saved and not reset.

You also lose lifecycle hooks like created, mounted, etc. since the component is not being rebuilt from scratch anymore. You can replace those lifecycle hooks with hooks that are specific to keep-alive components. For example:

Whether keep-alive is a disadvantage or advantage is entirely up to your scenario. If you want to keep the state because you want to switch fast and often between the keep-alive components, it could be an advantage. If you really rely on a clean state through components being built and destroyed, it could be a disadvantage.