Skip to content

messageboxBox 弹窗

基于 Dialog 组件,通过该组件,可以不用书写组件,快速调用 AlertConfirm

如果需要更复杂的逻辑结构,建议使用 Dialog 组件。

基础用法 Alert

Alert 一个弹窗。

查看代码
vue
<template>
	<demo-container>
		<gov-button @click="handleAlert">点击弹出Alert</gov-button>
	</demo-container>
</template>

<script setup>
import { GovMessageBox, GovMessage } from "@/dist/index.js";
const handleAlert = () => {
	GovMessageBox.alert({
		title: "友情提醒",
		content: "您正在访问GovUI,祝您心情愉快!",
	})
		.then(() => {
			GovMessage("点击了确定!");
		})
		.catch(() => {
			GovMessage("点击了关闭!");
		});
};
</script>

确认消息 Confirm

Confirm 一个弹窗。

查看代码
vue
<template>
	<demo-container>
		<gov-button @click="handleConfirm">点击弹出Confirm</gov-button>
	</demo-container>
</template>

<script setup>
import { GovMessageBox, GovMessage } from "@/dist/index.js";

const handleConfirm = () => {
	GovMessageBox.confirm({
		title: "请您确认",
		content: "你当前正在访问GovUI吗?",
	})
		.then(() => {
			GovMessage("点击了确定!");
		})
		.catch(() => {
			GovMessage("点击了关闭!");
		});
};
</script>

简写方式

如果你的弹出相对简单,你也可以直接传递一个字符串。

查看代码
vue
<template>
	<demo-container>
		<gov-button @click="handleQuickAlert">点击弹出Alert</gov-button>
		<gov-button @click="handleQuickConfirm">点击弹出Confirm</gov-button>
	</demo-container>
</template>

<script setup>
import { GovMessageBox } from "@/dist/index.js";
const handleQuickAlert = () => {
	GovMessageBox.alert("更加简洁的Alert!");
};
const handleQuickConfirm = () => {
	GovMessageBox.confirm("更加简洁的Confirm!");
};
</script>

Options

属性名说明类型可选值默认值
title对话框标题String"提示"
width对话框宽度String"450px"
content对话框内容String""
showCancelButton是否显示取消按钮Booleantrue, falsetrue
showConfirmButton是否显示确认按钮Booleantrue, falsetrue
cancelButtonText取消按钮文本String"取消"
confirmButtonText确认按钮文本String"确定"
cancelCallback取消按钮回调函数Function() => {}
confirmCallback确认按钮回调函数Function() => {}
closeCallback关闭对话框时的回调函数Function() => {}
closedCallback对话框关闭后的回调函数Function() => {}

Methods

方法名说明
alert弹出一个 alert 弹窗,返回promise。
confirm弹出一个 confirm 弹窗,返回promise。

Released under the MIT License.