对话框
覆盖在主窗口或其他对话框窗口上的窗口,使底层内容处于非活动状态。
安装
bash
npx shadcn-vue@latest add dialog
使用
vue
<script setup lang="ts">
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog'
</script>
<template>
<Dialog>
<DialogTrigger>
Edit Profile
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>
Make changes to your profile here. Click save when you're done.
</DialogDescription>
</DialogHeader>
<DialogFooter>
Save changes
</DialogFooter>
</DialogContent>
</Dialog>
</template>
示例
自定义关闭按钮
滚动主体
滚动覆盖层
表单
注释
要在 上下文菜单
或 下拉菜单
内激活 对话框
组件,必须将 上下文菜单
或 下拉菜单
组件包含在 对话框
组件中。有关更多信息,请参阅链接的 issue 此处.
js
<Dialog>
<ContextMenu>
<ContextMenuTrigger>Right click</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>Open</ContextMenuItem>
<ContextMenuItem>Download</ContextMenuItem>
<DialogTrigger asChild>
<ContextMenuItem>
<span>Delete</span>
</ContextMenuItem>
</DialogTrigger>
</ContextMenuContent>
</ContextMenu>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you absolutely sure?</DialogTitle>
<DialogDescription>
This action cannot be undone. Are you sure you want to permanently
delete this file from our servers?
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button type="submit">Confirm</Button>
</DialogFooter>
</DialogContent>
</Dialog>