你会实现一个微信小程序开关功能吗
wxml:
<view >
<button class="show" bindtap="onChangeShowState">{{showView?'隐藏':'显示'}}</button>
</view>
<view class="hide{{showView?'show':''}}">
<text class="text">我是被隐藏控件</text>
</view>
wxss:
.hide{
display: none;
}
.show{
display: block;
}
js:
Page({
data: {
showView: true
},
onLoad: function (options) {
showView: (options.showView == "true" ? true : false)
}
, onChangeShowState: function () {
var that = this;
that.setData({
showView: (!that.data.showView)
})
}
})
另一种方式:
wxml:
<image src="{{showView?'http://192.168.2.61/wap/rm/images/select.png':'http://192.168.2.61/wap/rm/images/selected.png'}}" bindtap="onChangeShowState"></image>
js:
showView:true;
onChangeShowState: function () {
var that = this;
that.setData({
showView: (!that.data.showView)
})
}
作者:Vam的金豆之路
主要领域:前端开发
我的微信:maomin9761
微信公众号:前端历劫之路