Vue $refs cannot be joined dynamically and cannot get objects

Source: Internet
Author: User

Original address: http://www.php.cn/js-tutorial-410304.html

This article brings to you the content is about Vue $refs do not use splicing reasons and solutions, there is a certain reference value, the need for friends can refer to, I hope to help you.

 <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  'audio'+index) {            Console.log (this. $refs);            Console.log (this. $refs. Audio[key])        }    )},

That would be an error.

In another way, remove the audio

Change to Console.log (this. $refs [key])
It still doesn't work.

That's what the official describes.

Change to the following form

<liclass="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) {ConstAudiolist = 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 ()})},

So I can get the DOM I want, and here I get the sub-components that loop out, and that's the reason for not using stitching in the Vue $refs and how to fix it.

Vue $refs cannot be joined dynamically, cannot get object (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.