原文地址: http://www.php.cn/js-tutorial-410304.html

 

本篇文章给大家带来的内容是关于vue $refs中不使用拼接的原因以及解决方法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

<li class="audio-item media" v-if="item.type == 3" @click="handleClearInterval(item.id)">
    <xm-audio :audioSrc="item.content" :size="item.size" :ref="'audio'+index"></xm-audio>
</li>
handleClearInterval(id) {
    _.each(this.$refs,(item,key)=>{
        if(key != 'audio'+index){
            console.log(this.$refs);
            console.log(this.$refs.audio[key])
        }
    })
},

这样写就会报错

vue $refs 无法动态拼接,获取不到对象(转)

 

换一种写法,去掉audio

改成console.log(this.$refs[key])
这样依旧不行

 

vue $refs 无法动态拼接,获取不到对象(转)

 

官方是这样描述的

vue $refs 无法动态拼接,获取不到对象(转)

 

改成如下形式

 

<li class="audio-item media" v-if="item.type == 3" @click="handleClearInterval(item.id)">
    <xm-audio :audioSrc="item.content" :size="item.size" ref="audio"></xm-audio>
</li>


handleClearInterval(id) { const audioList = this.filterListByType(this.info.instHomeworkContents,3) _.each(audioList,(item,key)=>{ if(item.id != id) { console.log(this.$refs) console.log(this.$refs.audio[key]); this.$refs.audio[key].clearInterval() } }) },

这样就能获取到想要的那个dom,我这里是获取了,循环出的子组件,以上就是vue $refs中不使用拼接的原因以及解决方法.

相关文章:

  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2021-12-19
猜你喜欢
  • 2023-01-23
  • 2022-12-23
  • 2023-01-23
  • 2022-02-16
  • 2023-01-23
  • 2022-12-23
  • 2023-03-18
相关资源
相似解决方案