Skip to content

Popup 弹出层

预览
01:38

组件名:rice-popup

弹出层容器,用于展示弹窗、信息提示等内容

平台兼容性

uni-app x

AndroidiOS鸿蒙Next微信小程序h5

基础使用

通过 v-model 可以控制 Popup 的显示,position 可以设置弹出的位置,默认为 center, 可选 top right bottom left

html
<rice-popup v-model:show="show" position="center" :closeable="false">
  <view class="popup-center">
    <rice-button type="primary" text="点我关闭" @click="show=false"></rice-button>
  </view>
</rice-popup>

<style>
.popup-center {
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  width: 150px;
  height: 150px;
}
</style>

样式

  • 通过设置 radius 可以得到一个圆角的弹窗
  • 通过 close-icon 可以设置关闭图标Icon值
  • 通过 duration 可以设置过渡时间
html
<rice-popup v-model:show="show4" position="bottom" radius="8px" close-icon="clear" :duration="600">
  <view class="popup-box">
    <rice-button type="primary" text="点我关闭" @click="show4=false"></rice-button>
  </view>
</rice-popup>

API

Props

属性名类型说明默认值
durationNumber动画时长,单位ms300
positionString位置,可选值:top、bottom、left、right、centercenter
z-indexNumberz-index值999
opacityBoolean是否使用透明度的渐变效果true
zoomBoolean是否使用缩放,对center 有效true
overlayBoolean是否显示遮罩层true
overlay-bg-colorString遮罩层的背景色-
closeableBoolean是否显示关闭图标true
close-iconString关闭图标的icon 名称-
close-icon-positionString关闭图标的位置,可选值:top-left、top-right、bottom-left、bottom-right-
close-on-click-overlayBoolean是否在点击遮罩层后关闭,默认true-
radiusString|Number圆角值,默认0px-
bg-colorString自定义背景色-
safe-area-inset-topBoolean是否开启顶部安全区适配,默认false-
safe-area-inset-bottomBoolean是否开启底部安全区适配,默认true-
before-closeFunction状态改变前的钩子, 返回 false 或者返回 Promise 且被 reject 则停止关闭,before-close 只会在用户点击关闭按钮或遮罩区域时被调用-
margin-topString|Number主要针对center-
custom-styleObject自定义style-

Events

事件名说明回调参数
open打开时触发-
close关闭时触发-
opened打开动画结束时触发-
closed关闭动画结束时触发-
clickOverlay点击遮罩层时触发-

Slot

名称说明
default自定义内容

类型定义

组件导出如下类型

ts
const popupRef=ref<RicePopupComponentPublicInstance|null>(null)