vue循环中点击选中再点击取消(单选)的实现
2020-09-16 04:08
2446 查看
没有展开时
点击展开之后
<div class="flashread_item_box_time"> <span class="moment_time">9分钟前</span> <div class="flashread_item_box_zan"> <span class="flashread_item_box_item"><i class="iconfont icon-changyongtubiao-mianxing-"></i>10</span> <span class="flashread_item_box_item" @click="tocomment(index)"><i class="iconfont icon-pinglun" :class="{showcolor:currentTab==index}"></i>10</span> </div> </div> <div class="comment_textareabox" :class="{'showcomment':currentTab==index}"> <div class="textarea_com"> <textarea placeholder="你来谈谈?" class="comment_textarea" v-on:input="change" v-model="comment"></textarea> <button class="btn_comment" :class="{'showcolor':showcombtn}">发表</button> </div> </div>
data(){ return{ currentTab:-1, flashreadlists:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], showcombtn:false, comment:'' } }, methods:{ change(){ if(this.comment.length>=1){ this.showcombtn=true }else{ this.showcombtn=false } }, tocomment(index){ if(index!=this.currentTab){ this.currentTab = index; }else{ this.currentTab = -1; } } }
补充知识:vue 循环多个标签,点击标签变色,再点击取消,可以同时点击多个
效果如下:
1.
<div class="relFacilityTitcon"> <i v-for="(item,index) in facilityList" :key="index" @click="changeSpan(index);" :class="{'bgcolor':spanIndex.indexOf(index)>-1}" >{{item}}</i> </div>
2.
.padding .relWarp .relFacility .relFacilityTitcon { /* border: 1px solid red; */ /* line-height: 20px; */ padding: 0 .24rem; font-size :10px; } .padding .relWarp .relFacility .relFacilityTitcon i { /* height:20px; */ display: inline-block; /* margin: 0 5px; */ height: 20px; line-height: 20px; padding: 0 .16rem; /* width: auto; */ font-size: 10px; color: #97979f; border-radius: 5px; border: 1px solid #97979f; margin-right: 10px; margin-top: 10px; font-style: normal; /* padding:1px 7px; */ /* display: inline-block; */ } .padding .relWarp .relFacility .relFacilityTitcon .bgcolor { border: 1px solid orange; color: orange; } .padding .relWarp .relFacility .relFacilityTitcon i:last-child { margin-right: 0; }
3.
methods: { changeSpan(index){ let arrIndex = this.spanIndex.indexOf(index); // console.log(arrIndex); if(arrIndex>-1){ this.spanIndex.splice(arrIndex,1); }else{ this.spanIndex.push(index); } },
以上这篇vue循环中点击选中再点击取消(单选)的实现就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:相关文章推荐
- html中点击radio后的文字相当于选中该单选按钮如何实现?怎么实现两个redio,选中一个,取消另一个?
- js练习,纯js实现 //选中变色 //隔行换色 //复选框点击全选 //复选框反选//复选框自动全选//复选框自动取消全选
- jQuery实现radio第一次点击选中第二次点击取消功能(转)
- 单选按钮radio点击已选中的,取消选中
- js简单的实现点击选中点击取消的效果
- jquery实现单选按钮选中与取消选中
- 点击按钮实现radio选中和取消(attr与prop的区别)
- Vue表格操作图片切换 点击查看大图 实现循环左右切换
- jQuery实现点击单选按钮切换选中状态效果
- vue 实现 点击取消监控内容是否发生修改 若修改提示 是否需要保存
- GridView单选效果 点击选中一项时,再点击选中另一项时改变背景,原来选中的项取消换回原来的背景
- vue实现点击选中,其他的不选中方法
- jquery实现radio按钮在分组状态下点击选中,再次点击取消选中
- 全部选中和删除选中商品的实现,点击一下全选,点击两下取消全选
- 【前端JS】radio 可单选可点击取消选中
- vue实现点击追加选中样式效果
- vue中实现点击追加选中样式,添加class名
- radio实现第一次点击选中第二次点击取消
- jQuery实现点击单选按钮切换选中状态效果
- 点击Html页面中Table上的tr 实现Tr前的checkbox选中或取消