The keep-alive hook functions can be activated or deactivated


keeps data in memory. If you want to fetch the latest data every time you enter the page, you need to fetch data in the Activated phase, which is used to fetch data in the original Created hook.

Components created within

have two more lifecycle hooks: activated and deactivated

Activated: called when the component is activated, when the component is rendered for the first time, and each subsequent keep-alive activation.

Deactivated: Invoked when a component is disabled.

Note: These two lifecycles will only be called if the component is wrapped in keep-alive. They will not be called if the component is used as a normal component. After version 2.1.0, exclude will not be called if the component is wrapped in keep-alive. This hook is also not called when rendering on the server.

When do you get the data?

When keep-alive is introduced, the hook activation sequence is created-> Mounted -> activated, and deactivated is triggered when the interface exits. When re-entering (forward or backward), only activated is triggered.

We know that after keep-alive, the page template is first decomposed into HTML fragments and then re-entered, instead of re-parsing, it will read the data in memory. That is, only when the data changes will VirtualDOM be used for diff updates. Therefore, the data that the page enters should also be retrieved in Activated. After the data is downloaded, manually manipulating the DOM should also be done in Activated.

Therefore, check that Activated contains a copy of the data retrieval code, or transfer the created code directly to Activated without creating the created code.

Handling the: www.cnblogs.com/goloving/p/…