Skip to content

Popup 弹出层

从屏幕边缘或中心弹出内容的容器组件。

基础用法

通过 v-model:show 控制弹出层的显示与隐藏。

vue
<template>
  <button @click="show = true">打开弹出层</button>

  <dr-popup v-model:show="show">
    <view class="content">弹出层内容</view>
  </dr-popup>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(false)
</script>

弹出位置

通过 position 属性设置弹出位置,支持 bottomtopleftrightcenter

vue
<!-- 底部弹出 -->
<dr-popup v-model:show="show" position="bottom">
  <view class="content">底部弹出</view>
</dr-popup>

<!-- 顶部弹出 -->
<dr-popup v-model:show="show" position="top">
  <view class="content">顶部弹出</view>
</dr-popup>

<!-- 左侧弹出 -->
<dr-popup v-model:show="show" position="left">
  <view class="content">左侧弹出</view>
</dr-popup>

<!-- 右侧弹出 -->
<dr-popup v-model:show="show" position="right">
  <view class="content">右侧弹出</view>
</dr-popup>

<!-- 中间弹出 -->
<dr-popup v-model:show="show" position="center">
  <view class="content">中间弹出</view>
</dr-popup>

关闭方式

默认点击遮罩层可以关闭弹出层,可以通过 mask-closable 属性禁用。

vue
<dr-popup v-model:show="show" :mask-closable="false">
  <view class="content">
    <text>点击遮罩不会关闭</text>
    <button @click="show = false">关闭</button>
  </view>
</dr-popup>

圆角设置

通过 border-radius 属性设置圆角大小。

vue
<dr-popup v-model:show="show" :border-radius="32">
  <view class="content">圆角弹出层</view>
</dr-popup>

API

Props

参数说明类型默认值
v-model:show是否显示弹出层booleanfalse
position弹出位置,可选值:bottom top left right centerstringbottom
mask-closable点击遮罩是否关闭booleantrue
show-mask是否显示遮罩层booleantrue
z-index层级number5000
safe-area-bottom是否适配底部安全区域booleantrue
border-radius圆角大小(rpx)number | string24
duration动画时长(ms)number300

Events

事件名说明回调参数
open打开弹出层时触发-
close关闭弹出层时触发-
opened打开动画结束后触发-
closed关闭动画结束后触发-

Slots

名称说明
default弹出层内容

基于 MIT 许可发布