Skip to content

Dialog 对话框

弹出一个对话框。

基本用法

你可以在任意位置弹出一个 Dialog对话框。

查看代码
vue
<template>
	<demo-container>
		<gov-button @click="visible = true">点击打开 Dialog</gov-button>
		<gov-dialog v-model="visible" title="标题" width="30%">
			<div>这是一个 Dialog!</div>
			<template #footer>
				<gov-button @click="visible = false">关闭</gov-button>
			</template>
		</gov-dialog>
	</demo-container>
</template>

<script setup>
import { ref } from "vue";
const visible = ref(false);
</script>

点击遮罩层关闭

默认点击遮罩层关闭,你可以设置 closeOnClickModalfalse 关闭该功能。

查看代码
vue
<template>
	<demo-container>
		<gov-button @click="visible = true">点击打开 Dialog</gov-button>
		<gov-dialog
			v-model="visible"
			title="标题"
			width="30%"
			:closeOnClickModal="false"
		>
			<div>这是一个 Dialog!点击遮罩层无法关闭哦!</div>
			<template #footer>
				<gov-button @click="visible = false">关闭</gov-button>
			</template>
		</gov-dialog>
	</demo-container>
</template>

<script setup>
import { ref } from "vue";
const visible = ref(false);
</script>

自定义标题

自定义标题内容。

查看代码
vue
<template>
	<demo-container>
		<gov-button @click="visible = true">点击打开 Dialog</gov-button>
		<gov-dialog v-model="visible" width="30%">
			<template #title>
				<div class="gradient-text">这是一个好看的标题</div>
			</template>
			<div>这是一个 Dialog!有自定义标题!</div>
			<template #footer>
				<gov-button @click="visible = false">关闭</gov-button>
			</template>
		</gov-dialog>
	</demo-container>
</template>

<script setup>
import { ref } from "vue";
const visible = ref(false);
</script>

<style lang="scss" scoped>
/* 从紫色到蓝色的渐变 */
.gradient-text {
	background-image: linear-gradient(to right, purple, blue);
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
	display: inline-block;
}
</style>

设置宽度

定义不同宽度。

查看代码
vue
<template>
	<demo-container>
		<gov-button @click="visible = true">点击打开 Dialog</gov-button>
		<gov-dialog v-model="visible" title="标题" width="600px" top="300px">
			<div>这是一个宽度 600px 居上高度 300px 的 Dialog!</div>
			<template #footer>
				<gov-button @click="visible = false">关闭</gov-button>
			</template>
		</gov-dialog>
	</demo-container>
</template>

<script setup>
import { ref } from "vue";
const visible = ref(false);
</script>

全屏模式

全屏模式可以覆盖整个视觉区域。

查看代码
vue
<template>
	<demo-container>
		<gov-button @click="visible = true">点击打开 Dialog</gov-button>
		<gov-dialog v-model="visible" title="全屏弹窗" fullscreen>
			<div>这是全屏的弹窗,别忘了关闭在右侧。</div>
		</gov-dialog>
	</demo-container>
</template>

<script setup>
import { ref } from "vue";
const visible = ref(false);
</script>

Attributes

属性名说明类型可选值默认值
modelValue控制对话框的显示与隐藏Booleantrue, falsefalse
title对话框标题String"提示"
closeOnClickModal点击遮罩层是否关闭对话框Booleantrue, falsetrue
showClose是否显示关闭按钮Booleantrue, falsetrue
width对话框宽度String"800px"
top对话框距离顶部的距离String"15vh"
fullscreen是否全屏显示Booleantrue, falsefalse
customClass自定义类名String""
beforeClose关闭前的回调函数Function

Events

事件名说明回调参数
change对话框显示状态改变时触发
open对话框打开时触发
opened对话框打开动画结束后触发
close对话框关闭时触发
closed对话框关闭动画结束后触发
update:modelValue更新对话框显示状态新的显示状态

Slots

插槽名说明作用域插槽内容
title自定义对话框标题内容可以放置自定义的标题内容
default对话框主体内容放置对话框的主要内容
footer对话框底部内容放置对话框底部的按钮或其他内容

Released under the MIT License.