微信小程序常见的demo

本文介绍了微信小程序中控制组件显示与隐藏的三种方法:方法一是通过数据控制显示状态;方法二是利用倒计时实现隐藏;方法三是使用wx:if和hidden。对比了wx:if与hidden的区别,wx:if适用于不频繁切换,hidden适合频繁切换,且hidden在页面结构中始终存在。
摘要由CSDN通过智能技术生成

1.微信小程序的显示和隐藏

方法一:

html部分

<button type="primary" bindtap="openPopup" data-index="1">打开弹窗</button>


<!-- 中间弹窗 -->
<view class="popup-box" wx:if="{
  {showIndex=='1'}}" bindtap="closePopup"></view>
<view class="info-center" style="top:{
  {height*0.045}}px;height:{
  {height*0.92}}px;" wx:if="{
  {showIndex=='1'}}">

  <view class="rese" bindtap="closePopup">
  X
</view>

</view>

js部分

Page({
  /**
   * 页面的初始数据
   */
  data: {
    showIndex:null,//打开弹窗的对应下标
    height:'',//屏幕高度
  },
  // 打开弹窗
  openPopup(e){
    var index = e.currentTarget.dataset.index;
    this.setData({
      showIndex:index
    })
  },
  //关闭弹窗
  closePopup(){
    this.setData({
      showIndex:null,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    var that = this;
    // 动态获取屏幕高度
    wx.getSystemInfo({
      success: (result) => {
        that.setData({
          height: result.windowHeight
        });
      },
    })
  },
})
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值