The difference between created and mounted in Vue lies in execution time and data access capabilities: created: called when the component is initialized. It can only access Vue instance data and cannot interact with the DOM. mounted: Called after DOM is mounted. It can access Vue instance data and DOM elements and interact with DOM.
The difference between created and mounted in Vue
In the life cycle of the Vue component, created
and mounted
are two crucial hook functions. They are used to perform specific tasks at different stages of a component, but they have some key differences in terms of execution time and availability.
Created
this.$mount()# in
new Vue() ## method is called immediately.
).
Mounted
).
Summary
created | mounted | |
---|---|---|
During component initialization | After DOM mounting | |
Vue instance data | Vue instance data and DOM elements | |
No | Yes |
created is used to perform data-related tasks during the component initialization phase, while
mounted is used during component loading Then perform DOM-related tasks.
The above is the detailed content of The difference between created and mounted in vue. For more information, please follow other related articles on the PHP Chinese website!