首页 > 解决方案 > 如何在 vuejs 中获取更新的 $refs

问题描述

变量更新后如何$refs在 Vuejs 中更新?

当我更新this.wordList时,我得到了旧词this.$refs.words

<div>
  <div class="list-container">
    <div ref='wordList' v-bind:style="wordListStyles" class="word-list">
      <div
        v-bind:class="{active: word.isActive, word: true, error: word.status === 2, success: word.status == 1 && !word.isActive}" 
        ref='words' v-for="word in wordList" v-bind:key="word.text"
      >{{word.text}}</div>
  </div>
</div>

我试图添加v-if和重新创建这样的组件:

reset() {
  this.showList = false;
  this.showList = true;
}

但这并没有帮助,以及这个答案https://stackoverflow.com/a/50044476/1037613

我知道参考不是实时的,但我需要它来获得每个单词的最高位置

this.wordRef[this.wordCount].getBoundingClientRect().top;

标签: vue.jsdynamicvue-componentref

解决方案


推荐阅读