P
P
Pavel Kleshnin2020-06-01 16:59:11
JavaScript
Pavel Kleshnin, 2020-06-01 16:59:11

Is there an alternative to querySelectorAll in Vue.js?

Actually, the question is in the title. For a single element, you can use $ref, but for several? Is it really possible to put ref="name1", ref="name2", ref="name3" every time?? If the elements are not drawn using a cycle, it somehow does not look very good.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Pautov, 2020-06-01
@shake_shake1

If you're using querySelectorAll to work with a component's template, then it looks like you're doing something wrong.
$ref is the only and essentially correct getting of the DOM element inside vue. $ref is essentially an id, there are no other things, only the indication of selectors for querySelectorAll.
If you have to give each DOM element a ref inside the 1st template, then again, most likely you are doing something wrong.
Show or tell in more detail what problem you are solving and most likely there is a better solution than what you are trying to do

A
Anton Anton, 2020-06-01
@Fragster

https://ru.vuejs.org/v2/guide/components-edge-case...

When ref is used in conjunction with v-for, then ref will be an array containing the child components rendered from the data source.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question