I am having a problem while accessing the DOM using Vue3 mounted hook.
I noticed that using the getElementById
or getElementByClassName
methods on the mounted hook, returns undefined, and using the querySelector
method returns the DOM.
After some research, I found that we should use nextTick
or asynchronous operations
to access the DOM in the mounted hook.
Doesn't the mounted hook itself mean the DOM is mounted?
Why do I need to use asynchronous operations
or nextTick
to get the DOM inside the mounted hook?
Plus:
I want to know the difference of getElementById
and getElementByClassName
? Why I can get DOM on the mounted hook By getElementById
,but I can not By getElementByClassName
.