title: Vue dynamically added :ref in v-for are not shown in this.$refs
body: <p>I'm new to vue.js, and I have a vue.js component that basically shows numbers from a data array when the button &quot;Add elements&quot; is clicked, the code is the following:</p>
  <pre><code>&lt;template&gt;
    &lt;div&gt;
      &lt;button @click=&quot;updateCounter&quot;&gt;Add elements&lt;/button&gt;
      &lt;div
        v-for=&quot;number in numsArray&quot;
        :key=&quot;number&quot;
        :ref=&quot;`${number}`&quot;
      &gt;
        &lt;div&gt;
          &lt;p&gt;{{ number }}&lt;/p&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
  import { SocketUpdate as socketUp } from &quot;./components/Data&quot;;
  
  export default {
    name: &quot;App&quot;,
    data() {
      return {
        numsArray: [],
        counter: 0,
      };
    },
    mounted() {
      console.log(&quot;REFS when mounted::&quot;, this.$refs);
    },
    beforeUpdate() {
      console.log(&quot;REFS before updated::&quot;, this.$refs);
  
    },
    updated() {
      console.log(&quot;REFS updated::&quot;, this.$refs);
    },
    methods: {
      updateCounter() {
        this.counter++;
        const copyOfArray = [...this.numsArray];
        copyOfArray.push(this.counter);
        this.numsArray = copyOfArray;
        console.log(this.numsArray);
      }
    },
  };
  &lt;/script&gt;
  
  &lt;style&gt;
  #app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
  }
  &lt;/style&gt;
  
  </code></pre>
  <p>However, 1. when the button is clicked and new elements are added to the numsArray and displayed in the v-for div, the <code>:ref=&quot;</code>${number}<code>&quot;</code> is never associated to the respective element, because when trying to print the <code>this.$refs</code> array in the mounted, updated or beforeUpdated hooks; that array empty (no refs) which means that the elements are created in the DOM, those numbers are visible, but the refs related to them are never created nor added to the <code>this.$refs</code> array. And 2. The <code>console.log(&quot;REFS...&quot;, this.$refs);</code> is only shown in the beforeUpdate when the button is clicked, and once in the mounted, so hows possible that the component passed through the beforeUpdate and not in the updated, if the data elements (numsArray in this case) were updated, do you know how exactly is the updated hook is invoked?</p>
  <p>Thanks you!</p>