Skip to content

Modal 模态框

模态弹窗,支持标题、内容、确认/取消按钮,常用于二次确认、信息提示等场景。

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

  • 通过 show 控制模态框显示/隐藏,支持 v-model 双向绑定。
html
<see-modal v-model:show="showModal" title="提示" content="确认删除该数据?" />

按钮类型

  • 通过 confirmType 设置确认按钮类型:primary(默认)、dangerwarning
html
<see-modal v-model:show="show" title="警告" content="此操作不可逆" confirmType="danger" />

关闭前钩子

  • 通过 beforeClose 在点击确认/取消前执行异步校验,返回 false 阻止关闭。
  • 钩子接收 'confirm''cancel' 参数,标识点击来源。
html
<see-modal v-model:show="show" title="提交" content="确认提交?" :beforeClose="onBeforeClose" />

<script setup>
const onBeforeClose = (action) => {
  if (action === 'confirm') {
    // 返回 false 阻止关闭
    return submitForm().then(() => true).catch(() => false)
  }
  return true
}
</script>

命令式调用

  • 通过 modal.confirm()modal.alert() 命令式调用,H5 端自动挂载真实组件实例。
ts
import { modal } from 'see-u-ui'

// 确认弹窗(含取消按钮)
const result = await modal.confirm({
  title: '提示',
  content: '确认删除?',
  confirmType: 'danger'
})
if (result.confirm) {
  // 用户点击确认
}

// 提示弹窗(仅确认按钮)
await modal.alert({
  title: '提示',
  content: '操作成功'
})

注意

命令式 API 在 H5 端通过 createApp 挂载真实 SeeModal 组件,支持所有 Props(包括 confirmTypebeforeClose 等)。在小程序/App 端回退到 uni.showModal,部分自定义属性不可用。

API

Props

参数名说明类型默认值
show是否显示(v-model)Booleanfalse
title标题String''
content内容文字String''
isShowHeader是否显示标题栏Booleantrue
isShowFooter是否显示底部按钮区Booleantrue
confirmText确认按钮文字String'确认'
cancelText取消按钮文字String'取消'
isShowCancelBtn是否显示取消按钮Booleantrue
confirmType确认按钮类型'primary' | 'danger' | 'warning''primary'
isConfirmLoading确认按钮加载状态Booleanfalse
isConfirmDisabled确认按钮禁用状态Booleanfalse
width模态框宽度String'600rpx'
zIndexz-index 层级Number1001
duration动画时长(ms)Number300
isCloseOnClickOverlay点击遮罩是否关闭Booleanfalse
isLockScroll是否锁定背景滚动Booleantrue
beforeClose关闭前钩子,接收 'confirm''cancel'((action: 'confirm' | 'cancel') => boolean | Promise<boolean>) | nullnull

Events

属性名说明回调参数
onConfirm点击确认按钮时触发-
onCancel点击取消按钮时触发-
onOpen模态框打开时触发-
onOpened打开动画结束时触发-
onClose模态框关闭时触发-
onClosed关闭动画结束时触发-
update:showv-model 更新value: boolean

Slots

插槽名说明
header标题栏内容
default内容区域
footer底部按钮区内容

辽 ICP 备 2025070134 号