Vue's ref is used as a binding element, why output an array?

HTML Code:

< ul class= "list" >

  <li class="item" 
  v-for="item of letters" 
  :key="item"
  :ref="item"
  @click="handleClick"
  @touchstart="handleTouchStart"
  @touchmove="handleTouchMove"
  @touchend="handleTouchEnd"
  >{{item}}</li>
</ul>

Logic Code:
handleTouchMove () {

  console.log("handleTouchMove");
  if (this.touchStatus) {
      const startY = this.$refs.A[0].offsetTop
      console.log(this.$refs.A); =====>,
      console.log(startY);
  }
},

data item: letters = [A recorder B recorder C recorder D recorder Ereco F recorder G recorder H repertory I recorder. Recorder Xpeng Ypeng Z]

I would like to ask you guys, when the ref here is used in the form of data binding, why does this.$refs.A print out an array?

clipboard.png

May.25,2021

this test is really strange
https://cn.vuejs.org/v2/api/-sharpref official advice seems not to allow ref to use data binding

I read the source code related to registerRef (), processRef, checkInFor and refInFor in this function.
when the element el of ref or parent has a list rendering, v-for will set refInFor to true
and then ref.key is set to an array in the registerRef function

.

this is a feature of vue, which automatically expands the ref in v-for into an array. Suppose your ref is not dynamic, but static ref= "a", then no matter how many times you execute the loop, the final ref will only have one value, so vue will convert the ref in v-for into an array in order to deal with this situation, in order to capture all ref values.

Menu