0👍
Update: I found the problem why it didn’t work.
The js code should be in mounted property. Not understanding 100% why like this is working and in inside created property not. I red about the differences, but if vue runs the created() hook when the component object is created, and before the component is mounted to the DOM my logic says it should work. So if someone know to explain me this I would be glad to read it.
Anyway, it’s working.
0👍
If you read the description of the created hook, you can see that at the end it mentions :
However, the mounting phase has not been started, and the $el property will not be available yet.
In the created hook, the component is not yet mounted and thus not available in the DOM yet ! You can also have a look at the lifecycle diagram to understand it better 🙂