微信小程序 实现动态显示和隐藏某个控件
1.wxml:
<view> <button bindtap="onChangeShowState">{{showView?'显示pieCanvas':'隐藏pieCanvas'}}</button> </view> <view class="{{showView?'view_show':'view_hide'}}"> <canvas canvas-id="pieCanvas" style="width:400px;height:280px;"></canvas> </view>2.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) }) }, }) 3.wxss:.view_hide{ display: none; } .view_show{ display: block; }














