Home > Web Front-end > JS Tutorial > Vue determines the usage of classes in the dom

Vue determines the usage of classes in the dom

php中世界最好的语言
Release: 2018-05-15 11:41:13
Original
2360 people have browsed it

This time I will bring you the use of vue to determine the class in the dom. What are the precautions for vue to determine the class in the dom. The following is a practical case, let's take a look.

vue clicks to add a class to the dom and then gets the dom containing the class

<p class="chose-ck" v-for="(item,index2) in colors" :key="index2" ref="chosebox">
                  <p>{{item.name}}</p>
                  <dt v-for="(item2,index) in item.childsCurGoods" :key="item2.id" :class="index==iac[index2]?&#39;check&#39;:&#39;&#39;" :id="item2.id" :data-chosename="item.name" :data-choseidname="item2.name" :data-chose="item.id" :data-id="item2.id" @click="chek(index2,index)" >
                    {{item2.name}}
                  </dt>
                </p>js
  chek(index2, index) {
      this.iac[index2] = index
      this.iac = this.iac.concat([]);
      this.checkchose()
    },
    checkchose:function(){
      var chose=this
      var chosedom=chose.$refs.chosebox
      console.log(chosedom)
      for (var i=0;i<chosedom.length;i++) {
        var children=chosedom[i].children
        for (var j=0;j<children.length;j++) {  
          if(children[j].className=="check")
          {
            console.log(children[j])
          }
        }
      }
    }
Copy after login

The dom obtained after clicking is printed

if(children[j].className=="check")
Copy after login

Added Determine why the printed dom is the dom before clicking

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese websiteOthersrelated articles!

Recommended reading:

Detailed explanation of the steps for vue to implement the mobile WeChat public account

Detailed explanation of the steps for adding a background mock interface in the vue-cli project

The above is the detailed content of Vue determines the usage of classes in the dom. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template