跳转到内容

抽屉 Drawer

$END$

点击触发按钮抽屉从右侧滑出,点击遮罩区关闭。

通过插槽自定义内容,或者设置相应属性来控制显示或隐藏。

通过函数的方式使用抽屉。

在抽屉内打开新的抽屉。

通过 popup-container 可以设置弹出层节点的挂载位置

自定义位置,点击触发按钮抽屉从相应的位置滑出。

参数名描述类型默认值版本
visible (v-model)抽屉是否可见booleanfalse
default-visible抽屉默认是否可见(非受控模式)booleanfalse
placement抽屉放置的位置'top' | 'right' | 'bottom' | 'left''right'
title标题string-
mask是否显示遮罩层booleantrue
mask-closable点击遮罩层是否可以关闭booleantrue
closable是否展示关闭按钮booleantrue
ok-text确认按钮的内容string-
cancel-text取消按钮的内容string-
ok-loading确认按钮是否为加载中状态booleanfalse
ok-button-props确认按钮的PropsButtonProps-2.9.0
cancel-button-props取消按钮的PropsButtonProps-2.9.0
unmount-on-close关闭时是否卸载节点booleanfalse2.12.0
width抽屉的宽度(仅在placement为right,left时可用)number|string250
height抽屉的高度(仅在placement为top,bottom时可用)number|string250
popup-container弹出框的挂载容器string | HTMLElement'body'
drawer-style抽屉的样式CSSProperties-
body-class抽屉内容部分的类名string | any[]-2.57.0
body-style抽屉内容部分的样式StyleValue-2.57.0
on-before-ok触发 ok 事件前的回调函数。如果返回 false 则不会触发后续事件,也可使用 done 进行异步关闭。( done: (closed: boolean) => void) => void | boolean | Promise<void | boolean>-
on-before-cancel触发 cancel 事件前的回调函数。如果返回 false 则不会触发后续事件。() => boolean-
esc-to-close是否支持 ESC 键关闭抽屉booleantrue2.15.0
render-to-body抽屉是否挂载在 body 元素下booleantrue
header是否展示头部内容booleantrue2.33.0
footer是否展示底部内容booleantrue2.11.0
hide-cancel是否隐藏取消按钮booleanfalse2.19.0
事件名描述参数版本
ok点击确定按钮时触发ev: MouseEvent
cancel点击取消、关闭按钮时触发ev: MouseEvent | KeyboardEvent
open抽屉打开后(动画结束)触发-
close抽屉关闭后(动画结束)触发-
before-open对话框打开前触发-2.43.0
before-close对话框关闭前触发-2.43.0
插槽名描述参数版本
header页眉-2.33.0
title标题-
footer页脚-

Drawer 提供的全局方法,可以通过以下三种方法使用:

  1. 通过 this.$drawer 调用
  2. 在 Composition API 中,通过 getCurrentInstance().appContext.config.globalProperties.$drawer 调用
  3. 导入 Drawer,通过 Drawer 本身调用

当通过 import 方式使用时,组件没有办法获取当前的 Vue Context,如 i18n 或 route 等注入在 AppContext 上的内容无法在内部使用,需要在调用时手动传入 AppContext,或者为组件全局指定 AppContext

import { createApp } from 'vue';
import { Drawer } from '@sdata/web-vue';
const app = createApp(App);
Drawer._context = app._context;
参数名描述类型默认值版本
placement抽屉放置的位置'top' | 'right' | 'bottom' | 'left''right'
title标题RenderContent-
content内容RenderContent-
mask是否显示遮罩层booleantrue
maskClosable点击遮罩层是否可以关闭booleantrue
closable是否展示关闭按钮booleantrue
okText确认按钮的内容string-
cancelText取消按钮的内容string-
okLoading确认按钮是否为加载中状态booleanfalse
okButtonProps确认按钮的PropsButtonProps-2.9.0
cancelButtonProps取消按钮的PropsButtonProps-2.9.0
width抽屉的宽度(仅在placement为right,left时可用)number | string250
height抽屉的高度(仅在placement为top,bottom时可用)number | string250
popupContainer弹出框的挂载容器string | HTMLElement'body'
drawerStyle抽屉的样式CSSProperties-
onOk点击确定按钮时触发(e?: Event) => void-
onCancel点击取消、关闭按钮时触发(e?: Event) => void-
onBeforeOk触发 ok 事件前的回调函数。如果返回 false 则不会触发后续事件,也可使用 done 进行异步关闭。( done: (closed: boolean) => void ) => void | boolean | Promise<void | boolean>-
onBeforeCancel触发 cancel 事件前的回调函数。如果返回 false 则不会触发后续事件。() => boolean-
onOpen抽屉打开后(动画结束)触发() => void-
onClose抽屉关闭后(动画结束)触发() => void-
onBeforeOpen抽屉打开前触发() => void-2.43.0
onBeforeClose抽屉关闭前触发() => void-2.43.0
escToClose是否支持 ESC 键关闭抽屉booleantrue2.15.0
header是否展示头部内容boolean | RenderContenttrue2.33.0
footer是否展示底部内容boolean | RenderContenttrue2.11.0
hideCancel是否隐藏取消按钮booleanfalse2.19.0
参数名描述类型默认值版本
close关闭抽屉() => void-
update更新抽屉(config: DrawerUpdateConfig) => void-2.43.2
参数名描述类型默认值
open打开抽屉(config: DrawerConfig, appContext?: AppContext) => DrawerReturn-