您好,欢迎来到96游戏网。
搜索
您的当前位置:首页怎样使用vue判断dom的class

怎样使用vue判断dom的class

来源:96游戏网
 这次给大家带来怎样使用vue判断dom的class,使用vue判断dom的class注意事项有哪些,下面就是实战案例,一起来看一下。

vue点击给dom添加class然后获取含有class的dom

<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])
 }
 }
 }
 
 }

点击过后获取到的dom打印

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

加了判断为什么打印出来的dom是点击之前的dom

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

Node.js+console输出日志文件实例分析

如何使用Vue实现拖拽效果

Copyright © 2019- 9603.com.cn 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务