博客列表 >微信小程序官方组件展示之视图容器page-container源码

微信小程序官方组件展示之视图容器page-container源码

软件事业部
软件事业部原创
2022年08月19日 09:05:30555浏览

以下将展示微信小程序之视图容器page-container源码官方组件能力,组件样式仅供参考,开发者可根据自身需求定义组件样式,具体属性参数详见小程序开发文档。
功能描述:
页面容器。
小程序如果在页面内进行复杂的界面设计(如在页面内弹出半屏的弹窗、在页面内加载一个全屏的子页面等),用户进行返回操作会直接离开当前页面,不符合用户预期,预期应为关闭当前弹出的组件。 为此提供“假页”容器组件,效果类似于 popup 弹出层,页面内存在该容器时,当用户进行返回操作,关闭该容器不关闭页面。返回操作包括三种情形,右滑手势、安卓物理返回键和调用 navigateBack 接口。
属性说明:

Bug & Tip:
1.tip: 当前页面最多只有 1 个容器,若已存在容器的情况下,无法增加新的容器
2.tip: wx.navigateBack 无法在页面栈顶调用,此时没有上一级页面
示例代码:
WXML:

  1. <view class="title">弹出位置</view>
  2. <view class="box">
  3. <button class="btn" bindtap="popup" data-position="right">右侧弹出</button>
  4. <button class="btn" bindtap="popup" data-position="top">顶部弹出</button>
  5. <button class="btn" bindtap="popup" data-position="bottom">底部弹出</button>
  6. <button class="btn" bindtap="popup" data-position="center">中央弹出</button>
  7. </view>
  8. <view class="title">弹窗圆角</view>
  9. <view class="box">
  10. <button class="btn" bindtap="changeRound">设置{{round ? '直角' : '圆角'}}</button>
  11. </view>
  12. <view class="title">遮罩层</view>
  13. <view class="box">
  14. <button class="btn" bindtap="changeOverlay">设置{{overlay ? '无' : '有'}}遮罩</button>
  15. <button class="btn" bindtap="changeOverlayStyle" data-type="black">黑色半透明遮罩</button>
  16. <button class="btn" bindtap="changeOverlayStyle" data-type="white">白色半透明遮罩</button>
  17. <button class="btn" bindtap="changeOverlayStyle" data-type="blur">模糊遮罩</button>
  18. </view>
  19. <page-container
  20. show="{{show}}"
  21. round="{{round}}"
  22. overlay="{{overlay}}"
  23. duration="{{duration}}"
  24. position="{{position}}"
  25. close-on-slide-down="{{false}}"
  26. bindbeforeenter="onBeforeEnter"
  27. bindenter="onEnter"
  28. bindafterenter="onAfterEnter"
  29. bindbeforeleave="onBeforeLeave"
  30. bindleave="onLeave"
  31. bindafterleave="onAfterLeave"
  32. bindclickoverlay="onClickOverlay"
  33. custom-style="{{customStyle}}"
  34. overlay-style="{{overlayStyle}}"
  35. >
  36. <view class="detail-page">
  37. <button type="primary" bindtap="exit">推出</button>
  38. </view>
  39. </page-container>

WXSS:

  1. page {
  2. background-color: #f7f8fa;
  3. color: #323232;
  4. width: 100%;
  5. height: 100%;
  6. }
  7. .box {
  8. margin: 0 12px;
  9. }
  10. .title {
  11. margin: 0;
  12. padding: 32px 16px 16px;
  13. color: rgba(69, 90, 100, 0.6);
  14. font-weight: normal;
  15. font-size: 18px;
  16. line-height: 20px;
  17. text-align: center;
  18. }
  19. .btn {
  20. display: block;
  21. width: 100%;
  22. margin: 10px 0;
  23. background-color: #fff;
  24. }
  25. .detail-page {
  26. width: 100%;
  27. height: 100%;
  28. min-height: 300px;
  29. display: flex;
  30. align-items: center;
  31. justify-content: center;
  32. }

版权声明: 本站所有内容均由互联网收集整理、上传,如涉及版权问题,我们第一时间处理。
原文链接地址:
https://developers.weixin.qq.com/miniprogram/dev/component/page-container.html

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议