@pweil This is correct! Multiple HTML elements can have the same reference. Because of that you always have an array.
Here is another example: https://jsfiddle.net/choasia/3xj7afgh/1/ (check your developer console for the results)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've got a form fieldset of checkboxes ("areas") in a blade file. Each area has an id and a name, and the areas are stored as an array of objects in a Vuex store. When I loop through the areas array using v-for, I am assigning a ref to each checkbox input. What's puzzling me is why each ref is itself an array. I've never seen that before. So in order to, say, move the focus to the first checkbox, I need to write
this.$refs.area_1[0].focus()
Which feels odd. I must be missing something -- can anyone explain this?
Here is the loop:
<div v-for="area of areaSet">
<input
type="checkbox"
name="area_id[]"
:value="area.id"
v-model.number="$v.form_areas.$model"
:id="'area_' + area.id"
:ref="'area_' + area.id"
>
<label :for="'area_' +area.id" class="checkbox">
@{{ area.area_name }}
</label>
</div>
In Vue Devtools, the relevant $refs are listed like this:
area_1:Array[1]
0:<input id="area_1">
area_10:Array[1]
0:<input id="area_10">
area_11:Array[1]
0:<input id="area_11">
area_2:Array[1]
0:<input id="area_2">
area_3:Array[1]
0:<input id="area_3">
@pweil This is correct! Multiple HTML elements can have the same reference. Because of that you always have an array.
Here is another example: https://jsfiddle.net/choasia/3xj7afgh/1/ (check your developer console for the results)
Please or to participate in this conversation.