Lifecycle Hooks
Lifecycle hooks allow for code to run at different stages of an applications lifecycle.
Lifecycle hooks need to be imported from vue -
Mounted Hooks
Before Mount
Code will run just before the component is loaded to the browser
On Mount
Code will run when the component is loaded
Before Mount
Code will run just before the component is removed from the browser
On Unmount
Code will run after component has been removed from the browser
Activated Hooks
In order to use these hooks a 'keep alive' tag needs to be used in the main template where the router is used -
To achieve this replace this -
With this -
Activated Hook
This hook will only run if the component is being actively kept alive
Deactivated Hook
This hook will run when the component is no longer being kept alive
Updated Hooks
These hooks run whenever a component is updated.
Before Update
This hook will run when a component is updated just before the change occurs on screen
Updated
This hook will run the moment a component is updated