A
A
Alianos2021-04-19 21:56:01
Vue.js
Alianos, 2021-04-19 21:56:01

How are $refs/v-el/id/ different in VUE 2 CLI?

Hello, we can always access an object using an id, but we cannot use the same id on different objects. Why is $refs / v-el special?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-04-20
@Alianos

Hello, we can always access the object using id

No not always. If the object is outside the current scope and it is not specially imported in any way, then we do not have access to it. So I guess you mean DOM elements?
Why is $refs / v-el special?
Vue takes care of all the work with the DOM. And during its operation, as much as we would not like, references to DOM elements may lose their relevance. Any redrawing of an element is the loss of relevance of all links leading to it, obtained through, say, document.getElementById( id );.
Here comes the stage $refs. When the element is redrawn, the reference to this.$refsit also changes. We can be sure that the link is working at any time.
In addition, if the element is hidden by means , then you will not get access to it in any way, exceptv-ifthis.$refs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question