Skip to content

mp-dialog 消息弹窗

支持通过 hooks 和 props 两种方式控制显示

代码演示

通过 hooks 方法控制显示

我们强烈建议使用 hooks 方法来控制组件的显示状态,而 mp-dialog 组件仅用作一个挂载组件。

基本使用:

vue
<script setup>
import {useDialog} from '@ifanrx/uni-mp'

const {showDialog} = useDialog()

showDialog({
  title: '提示',
  content: '这是一条提示信息',
})
</script>

<template>
  <!-- 配合挂载 mp-dialog 组件 -->
  <mp-dialog ref="$dialog" />
</template>

详细使用方法见:弹窗控制 Hooks

通过 props 控制显示

当然现有 hooks 不满足使用,你也可以通过传入 props 来控制显示,以适配更多场景:

vue
<template>
  <mp-dialog :visible="true" title="标题" @confirm="onConfirm" />
</template>

禁止页面滚动

介绍文档:禁止页面滚动

API

Props

Prop nameDescriptionTypeValuesDefault
visible v-model显示弹窗boolean-
type提示类型string-''
mode弹窗模式string-'base'
title提示标题string-''
content提示内容,若不传则使用 slot 内容string-''
confirmText确认按钮文案string-'确定'
cancelText取消按钮文案string-'取消'
confirmColor确认按钮颜色string-'#007aff'
cancelColor取消按钮颜色string-'#333'
showCancelboolean-true
showConfirmboolean-true
value输入框值string-''
inputType输入框值string-'text'
placeholder输入框占位文本string-''
beforeClose点击按钮自动关闭,若设置为 false,则需要手动调用 close 方法boolean-true
maskClosable允许点击遮罩关闭弹窗boolean-false

Expose

setOptions

(options: object) => void

设置 dialog 选项

open

() => void

打开 dialog

close

() => void

关闭 dialog

Events

Event namePropertiesDescription
confirmargs any - 参数点击确认时触发
cancelargs any - 参数点击取消时触发

Slots

NameDescriptionBindings
default弹窗内容,仅在 base 模式下生效

源码

组件示例