Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue difference of refs and javascript method like getElementById

I know both can make me to access to a element but what is the difference?
It is only difference that Refs is more easier to access the element?

like image 887
kkokki Avatar asked Jun 07 '26 12:06

kkokki


1 Answers

Assuming that you're speaking about template refs, the main benefit of such usage is that you stay in VueJS' reactivity realm. Hence, you don't mix Vue and vanilla JS.

Then, AFAIK template refs are reactive in Vue3, so it will bring even more benefit because you will need less back and forth regarding any updates to specific DOM manipulations (as opposing to vanilla JS).

like image 185
kissu Avatar answered Jun 10 '26 09:06

kissu