Vue.js documentation describes the created
and mounted
events as follows:
created
Called synchronously after the instance is created. At this stage, the instance has finished processing the options which means the following have been set up: data observation, computed properties, methods, watch/event callbacks. However, the mounting phase has not been started, and the $el property will not be available yet.
mounted
Called after the instance has just been mounted where el is replaced by the newly created vm.$el. If the root instance is mounted to an in-document element, vm.$el will also be in-document when mounted is called.
This hook is not called during server-side rendering.
I understand the theory, but I have 2 questions regarding practice:
- Is there any case where
created
would be used overmounted
? - What can I use the
created
event for, in real-life (real-code) situation?
created
is called earlier, so it makes sense to trigger data fetching from API backend for example. – Egor Stambakiocreated()
to dispatch actions for api calls. – chovy