eg:
<view class='orderBox'>
<view class="orderList" wx:for="{{orderList}}" wx:key="id">//wx:for循环的列表(大家都懂得)
<text class="{{index==idx?'_left':'left'}}" bindtap='goIndex' data-index="{{index}}">{{item.text}}</text> //class后面的是三元运算符(小程序也是有的哦(解释:如果index=idx就执行_left的状态,否则执行 left的状态))
<text class="{{index==idx?'_right':'right'}}" data-id="{{id}}"></text>
</view>
</view>
.left{
font-size: 32rpx;
color: #595959;
}
._left{ //此class名是点击之后改变的状态(自己可以修改,这个是字体的颜色和大小)
font-size: 32rpx;
color: #F7423E;
}
._right{
width: 66rpx;
height: 4rpx;
background: #F7423E;
border-radius: 4px;
margin-top: 24rpx;
}
data:{
idx: 0, //默认熊0开始
xiahx:0 //默认熊0开始
}
//点击切换隐藏和显示
goIndex(e) {
let index = e.currentTarget.dataset.index; //获取当前点击的下标
console.log('每个index',index)
},
goIndex(e) {
let index = e.currentTarget.dataset.index; //获取当前点击的下标
// console.log('每个index',index)
this.setData({ //data 这次要改变的数据 通过this.setdata将改变的数据重新渲染页面
idx: index 当前的下标等于获取到的下标
})
},