实现非常简单,通过一个简单的判断当前data中的选中值,点击按钮时更新data值,重新渲染页面。
index.wxml文件
<view class="switch-type">
"btn {{currentSelectTripType == 'pinche' ? 'active' : ''}}" bindtap='selectedPinche' data-id='pinche'>拼车</view>
"btn {{currentSelectTripType == 'baoche' ? 'active' : ''}}" 'selectedBaoche' 'baoche'>包车</view>
</view>
index.js文件
Page({
data: {~~~~
currentSelectTripType: 'pinche',},
selectedPinche: function (e) {
this.setData({
currentSelectTripType: e.currentTarget.dataset.id
})
},selectedBaoche: function(e) {
附上一个简单的样式
index.wxss
.switch-type {
display: flex;
}
.switch-type .btn:first-child {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.switch-type .btn:last-child {
border-top-left-radius: border-bottom-left-radius: 0;
}
.switch-type .btn {
background: #dfdfdf;
padding: 10rpx 40rpx;
}
.switch-type .btn.active {
border: 2rpx solid #007bff;
#fff;
} (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|