Home > Article > Web Front-end > Which one is executed first, created or mounted in vue?
In the Vue life cycle, the created hook is executed before mounted. The created hook is used to perform DOM-free operations when the component is instantiated, while the mounted hook is used to perform DOM-related operations after the component is mounted.
The execution order of created and mounted in the Vue life cycle
The execution order of created and mounted in the Vue life cycle Two important hook functions are used to perform specific tasks at different life cycle stages of the component. The execution order between them is as follows:
1. The created
created hook function is executed immediately after the component instance is created. At this time, the DOM element of the component has not yet been create. Mainly used to perform the following tasks:
2. mounted
mounted hook function is executed after the component is mounted on the DOM. At this time, the DOM element of the component is already available. Mainly used to perform the following tasks:
Execution order
According to the Vue life cycle, the created hook function is executed first before the mounted hook function. This is because the created hook function is executed when the component is instantiated, while the mounted hook function is executed after the component is mounted on the DOM.
So if you need to perform any action before relying on the DOM element, do it in the created hook function. If you need to perform operations after the component is mounted, you can use the mounted hook function.
The above is the detailed content of Which one is executed first, created or mounted in vue?. For more information, please follow other related articles on the PHP Chinese website!