uni-app中點擊相應按鈕變色,其他按鈕則不變色


需求:初始化高亮第一個按鈕,然后點擊其他按鈕時,點擊的按鈕變色,未點擊的以及曾點擊過的按鈕則恢復成未點擊的顏色

 

由於第一個按鈕是獨立寫的,不在遍歷內,所以要單獨寫判斷,這里我用的Sum這個,代碼中就不細寫

1 <button  :class="active == Sum ? 'active':'anliu'"   type="default"  @click="all()"><view class="yonghu">總用戶</br>{{Sum}}</view></button>
2                         <view  v-for="(item, index) in sequList"  :key="index" >
3                             <button :class="active == item ? 'active':'anliu'"   type="default"   @click="sequ(item,index)"><view class="yonghu1">{{item.communityName}}</br>{{item.sum}}戶</view></button>
4                         </view>
1 data() {
2             return {
3                 active:'',
4             }
5 }
 1 // 總社區
 2             all(){
 3                 // console.log('總');
 4              //    console.log(this.Sum);
 5                 this.active = this.Sum;
 6                 
 7                     var tid=this.sequList[0].communityParentId ;
 8                     // console.log(tid);
 9                     // 請求到所有數據
10                     ajax.getshequuser({
11                         userId: this.userId,
12                         
13                         communityId:tid
14                     }).then(res => {
15                         // this.manageManBack(res);
16                         console.log(res)
17                         // console.log(res.data);
18                         this.manageManBack(res);
19                         uni.showToast({
20                             title: '當前顯示為全部用戶列表!',
21                             icon: 'none',
22                         })
23                     })
24                 
25                 
26                 
27             },
28             // 社區按鈕
29             sequ(item,index){
30                 
31                 // console.log(item,index);
32                 this.active = item;
33                 // 社區id
34                 this.sequId=item.communityId;
35                 ajax.getshequuser({
36                     userId: this.userId,
37                     // communityId: cId
38                     communityId:this.sequId
39                 }).then(res => {
40                     this.manageManBack(res);
41                     // this.disabledA=false;
42                     console.log(res);
43                     uni.showToast({
44                         title: '當前顯示為'+item.communityName+'列表!',
45                         icon: 'none',
46                     })
47                 })
48             },
 1 .anliu{
 2         width: 165upx;
 3         height: 145upx;
 4         background:#f84201 ;
 5         float: left;
 6         margin-left: 18upx;
 7         margin-bottom: 10upx;
 8         margin-top: 20upx;
 9         font-size: 24upx;
10         color: #ffffff;
11         line-height:40upx;
12         
13     }
14 .active {
15      
16      width: 165upx;
17      height: 145upx;
18      background-color: #aa0000;
19      float: left;
20      margin-left: 18upx;
21      margin-bottom: 10upx;
22      margin-top: 20upx;
23      font-size: 24upx;
24      color: #FFFFFF;
25      line-height:40upx;
26      }

初始化的時候第一個總計按鈕高亮的話,則直接將該方法在初始化時調用即可

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM