Skip to content

Popup 弹出层

介绍

弹出层容器,用于展示弹窗、信息提示等内容,支持多个弹出层叠加展示。

基础用法

通过设置 visible 控制显示 / 隐藏。

html
<template>
  <nut-popup v-model:visible="visible"></nut-popup>
</template>
ts
const visible = ref(false);

弹出位置

通过设置 position 来控制弹出位置。

html
<template>
  <nut-popup v-model:visible="visible" position="center"></nut-popup>
  <nut-popup v-model:visible="visible" position="top"></nut-popup>
  <nut-popup v-model:visible="visible" position="right"></nut-popup>
  <nut-popup v-model:visible="visible" position="bottom"></nut-popup>
  <nut-popup v-model:visible="visible" position="left"></nut-popup>
</template>

图标

通过 closeable 控制图标是否可关闭,close-icon-position 设置图标的位置,close-icon 自定义显示图标, 参考 图标

html
<template>
  <nut-popup v-model:visible="visible" closeable></nut-popup>

  <nut-popup v-model:visible="visible" closeable close-icon-position="top-left"></nut-popup>

  <nut-popup v-model:visible="visible" closeable>
    <template #close-icon>
      <nut-icon name="heart"></nut-icon>
    </template>
  </nut-popup>
</template>

圆角弹框

通过设置 round 来控制是否显示圆角。

html
<template>
  <nut-popup v-model:visible="visible" round></nut-popup>
</template>

多层堆叠

html
<template>
  <nut-popup v-model:visible="visible1">
    <text @tap="visible2 = true">打开第 2 层</text>
  </nut-popup>

  <nut-popup v-model:visible="visible2">正文</nut-popup>
</template>

API

Props

参数说明类型可选值默认值
v-model:visible控制当前组件显示 / 隐藏boolean-false
position弹出位置stringcenter / top / right / bottom / leftcenter
transition动画名string--
pop-class自定义弹框类名string--
round是否显示圆角boolean-false
closeable是否显示关闭按钮boolean-false
close-icon图标名称 或图片链接string-close
close-icon-position关闭按钮位置stringtop-left / top-right / bottom-left / bottom-righttop-right
destroy-on-close弹层关闭后 slot 内容是否销毁boolean-true
overlay是否显示遮罩boolean-true
safe-area-inset-bottom是否开启 iphone 系列全面屏底部安全区适配(仅 positionbottom 时有效)boolean-false
safe-area-inset-top是否开启 iPhone 顶部安全区适配(仅 positiontop 时有效)boolean-true
z-index遮罩层级number-2000+
duration组件显示 / 隐藏的动画时长(单位:msstring / number-300
overlay-class自定义遮罩层类名string--
overlay-style自定义遮罩层样式CSSProperties--
lock-scroll H5背景是否锁定boolean-false
close-on-click-overlay是否点击遮罩关闭boolean-true

Events

事件名说明类型
click-pop点击弹出层时触发(event: Event) => void
click-close-icon点击关闭图标时触发() => void
click-overlay点击遮罩触发() => void
open打开弹框时触发() => void
opened遮罩打开动画结束时触发() => void
close关闭弹框时触发() => void
closed遮罩关闭动画结束时触发() => void

Slots

名称说明
default自定义内嵌内容
close-icon关闭按钮的自定义图标

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值
--nut-popup-close-icon-margin16px
--nut-popup-border-radius20px

MIT Licensed