vue循環(huán)中點擊選中再點擊取消(單選)的實現(xiàn)
更新時間:2020年09月10日 08:34:23 作者:Archer_yy
這篇文章主要介紹了vue循環(huán)中點擊選中再點擊取消(單選)的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
沒有展開時
點擊展開之后
<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="你來談?wù)劊? class="comment_textarea" v-on:input="change" v-model="comment"></textarea> <button class="btn_comment" :class="{'showcolor':showcombtn}">發(fā)表</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 循環(huán)多個標簽,點擊標簽變色,再點擊取消,可以同時點擊多個
效果如下:
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循環(huán)中點擊選中再點擊取消(單選)的實現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue-vuex中使用commit提交mutation來修改state的方法詳解
今天小編就為大家分享一篇vue-vuex中使用commit提交mutation來修改state的方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09vue+element-plus上傳圖片及回顯問題及數(shù)量限制
本文主要介紹了vue+element-plus上傳圖片及回顯問題及數(shù)量限制,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04詳解vue 中使用 AJAX獲取數(shù)據(jù)的方法
本篇文章主要介紹了詳解vue 中使用 AJAX獲取數(shù)據(jù)的方法,在VUE開發(fā)時,數(shù)據(jù)可以使用jquery和vue-resource來獲取數(shù)據(jù),有興趣的可以了解一下。2017-01-01vue3+ts+Vuex中使用websocket協(xié)議方式
這篇文章主要介紹了vue3+ts+Vuex中使用websocket協(xié)議方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10vue-router 源碼之實現(xiàn)一個簡單的 vue-router
這篇文章主要介紹了vue-router 源碼之實現(xiàn)一個簡單的 vue-router,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07基于Vue中點擊組件外關(guān)閉組件的實現(xiàn)方法
下面小編就為大家分享一篇基于Vue中點擊組件外關(guān)閉組件的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03