uniapp 点击按钮时改变颜色,点击结束后恢复原颜色

uniapp 点击按钮时改变颜色,点击结束后恢复原颜色

复制代码
 1 <template>
 2     <view class="container">
 3         <view class="listbox">
 4             <view class="sublistbox">
 5                 <view class="box30">
 6                     <text class="txt-fontsize14-gray">充值金额:</text>
 7                 </view>
 8                 <view class="box40">
 9                     <input class="priceinput" type="text" value="" v-model="price"/>
10                 </view>
11                 <view class="box30">
12                     <text class="txt-fontsize14-gray">元</text>
13                 </view>
14             </view>
15             <view class="pricelistbox" >
16                 <view class="pricebox" v-for="(item,index) in priceList" :key="index" @tap="priceChange(index)">
17                     <view class="priceinerbox"  :class="{active:item.isSelect}">
18                         <text class="txt-fontsize16">{{item.name}}</text>
19                     </view>
20                     
21                 </view>
22             </view>
23         </view>
24     </view>
25 </template>
26 <script>
27     export default {
28         data() {
29             return {
30                 price: 0,
31                 priceList:[{name:'+100',value:100,isSelect:false},{name:'+200',value:200,isSelect:false},{name:'+500',value:500,isSelect:false},
32                         {name:'+1000',value:1000,isSelect:false},{name:'+2000',value:2000,isSelect:false},{name:'清零',value:0,isSelect:false}]
33             }
34         },
35         methods: {
36             priceChange(n) {
37                 var p=this.price;
38                 var _this=this;
39                 _this.priceList[n].isSelect=true;
40                 if(n==5){
41                     this.price=0;
42                 }
43                 else{
44                     this.price=p+this.priceList[n].value
45                 }
46                 setTimeout(function() {
47                   _this.priceList[n].isSelect=false;
48                  }, 300);
49             }
50         }
51     }
52 </script>
53 
54 <style>
55     .pricelistbox{
56         width: 94%;
57         height: 20vh;
58         display: flex;
59         flex-direction: row;
60         flex-wrap: wrap;
61         justify-content: center;
62         align-items: center;
63     }
64     .pricebox{
65         width: 30%;
66         display: flex;
67         flex-direction: column;
68         justify-content: center;
69         align-items: center;
70     }
71     .priceinerbox{
72         width: 90%;
73         height: 7vh;
74         border: 2px solid #66CDAA;
75         border-radius: 10px;
76         display: flex;
77         flex-direction: column;
78         justify-content: center;
79         align-items: center;
80     }
81     .active{
82         background-color: #66CDAA;
83         color: white;
84     }
85 </style>
复制代码

 

posted @   中国结  阅读(7892)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
点击右上角即可分享
微信分享提示