问题描述:
点击商品的“立即购买”按钮后会有“+1”的字样出现,一秒钟后又再次消失。
效果:
思路:
将“+1”效果设置显示和隐藏,以商品list的属性存储,当点击按钮时利用setTimeout函数设置显示1秒钟
wxml
<view class="special1 {{item.addlabel==0?'none':''}}" >+1</view><button data-index="{{index}}" class="buy-now" bindtap="newBuy">立即购买</button>.wxss
.none{ display:none;}js:(同时含有计算总价和总数量的方法)
newBuy:function(e){ const index = e.currentTarget.dataset.index; <!--newUrl是商品信息的list--> let newUrl = this.data.newUrl; <!--先“+1”字样设置为出现,即让addlabel设置为0--> newUrl[index].addlabel = 1; this.setData({ newUrl: newUrl }), <!--setTimeout是设置内容延迟几秒后执行,所以设置延迟1秒后将addlabel置为0,字样消失--> setTimeout(function () { newUrl[index].addlabel = 0; if (newUrl[index].addlabel == 0) { this.setData( { newUrl: newUrl, } ); } }.bind(this), 1000) },













