你會實現(xiàn)一個微信小程序開關(guān)功能嗎

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的金豆之路

主要領(lǐng)域:前端開發(fā)

我的微信:maomin9761

微信公眾號:前端歷劫之路