Home >Web Front-end >JS Tutorial >Vue determines the usage of classes in the dom
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]?'check':''" :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]) } } } }
The dom obtained after clicking is printed
if(children[j].className=="check")
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!