Home >Web Front-end >JS Tutorial >Reasons and solutions for not using splicing in vue $refs

Reasons and solutions for not using splicing in vue $refs

不言
不言Original
2018-09-17 14:12:194439browse

This article brings you the reasons and solutions for not using splicing in vue $refs. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

It is best not to use splicing in ref


  •     
  • handleClearInterval(id) {
        _.each(this.$refs,(item,key)=>{
            if(key != 'audio'+index){
                console.log(this.$refs);
                console.log(this.$refs.audio[key])
            }
        })
    },
    will report an error if you write it this way

    Reasons and solutions for not using splicing in vue $refs

    Change the way of writing, remove audio

    and change it to console.log(this.$refs[key])
    This still doesn’t work

    Reasons and solutions for not using splicing in vue $refs

    This is the official description

    Reasons and solutions for not using splicing in vue $refs

    Change to the following form

    
    
  •     
  • 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()
        }
      })
    },

    This way you can get the dom you want. Here I get it, loop out the sub-component, and then call the sub-component clearInterval() method.

    The above is the detailed content of Reasons and solutions for not using splicing in vue $refs. For more information, please follow other related articles on the PHP Chinese website!

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn