vue created lifecycle hook
In vuejs there is the vue created lifecycle hook method that can be used to define some logic that should run after the vue instance is created, but before the vue is mounted to a mount point in html via the vue el option or the mount instance method.
This created option of life cycle hook if you prefer is one of many hook methods that can be used when creating a vue instance to define some logic that will happen at the various stages of the vue instance lifecycle. There is another hook that can be used to do something before even the data object is there to work with, and there is also a mounted hook that can be used to define something to do once that data object is there to work with, and the the vue instance is mounted to the hard coded html. There is also an before updated, and updated hooks that will fire each time a change is made to an observable property of the data object.
In this post I will be focusing mostly on just the created hook, but I will also be touching base on life cycle hooks in general actually.
1 - Vue create lifecycle hook basic example
For a basic example of the vue created lifecycle hook here is a quick example that logs the value of a vue data object property, and the current value of the $el property as well. The vue created hook fires after the vue instance is created, so the value in the data object is present at this time. However the value of $el is undefined because the vue instance has not yet been mounted to the html document mount point selected via the vue el option, or the $mount instance method.
2 - Vue created is called synchronously
The vue created hook is called synchronously so anything that might evolve heavy lifting that is not delayed some how will delay the lifecycle from preceding to the mount hook.
Getting into how to address these kinds of problems might be a little off topic, but the basic thing here is to just be aware of how much overhead something might take up. There is breaking things down and only updating a few things each tick, or pushing work off into a webworker which is what should happen in situations in which there is to much going on in a life cycle hook.
3 -Vue el, vue $mount, and the vue create hook
If the vue el option is not used when creating the vue instance then the lifecyle process will come to a halt after the created hook until the $mount method is used to mount the instance to a mount point in the html document. So then the created hook is the last hook that will fire until the mounted method is used, at which point the life cycle of the instance will progress the the mounted hook.
4 - Conclusion
The created lifecycle hook is fired after the vue instance is created, but before the instance is mounted to the hard coded html. Often I find myself using the mounted lifecycle hook so that I have everything to work with when it comes to doing something for the first time such as calling a draw method for a canvas element or something to that effect. Still the created hook is there for when I want to do something with the data object before the instance is mounted to html.