微信小程序tab菜单切换实现选中效果 三元运算方法
微信小程序tab菜单切换实现选中效果 用到三元运算方法
wxml:
<view class='topmenu'>
<view wx:for="{{lmlist}}" data-id='{{item.id}}' class="taga-item-{{currentItem==item.id?'active-tag':''}}" bindtap="tagChoose">{{item.typename}}</view>
</view>
js:
tagChoose: function (options) {
var that = this
var id = options.currentTarget.dataset.id;
console.log(id)
//设置当前样式
that.setData({
'currentItem': id
})
}
wxss:
.taga-item-active-tag{
color: #d4237a
}
THE END