vue如何判断dom的class
程序员文章站
2023-01-18 17:30:14
vue点击给dom添加class然后获取含有class的dom
vue点击给dom添加class然后获取含有class的dom
<div 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> </div>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]) } } } }
点击过后获取到的dom打印
if(children[j].classname=="check")
加了判断为什么打印出来的dom是点击之前的dom
总结
以上所述是小编给大家介绍的vue如何判断dom的class,希望对大家有所帮助
上一篇: 辉腾与帕萨特的搞笑对话