Drawer 抽屜
從螢幕一側滑出的面板,用來放詳情、表單、設定這類內容比較多、又不想跳轉頁面的東西。內容很少、只是確認一下時用 Modal。
引入
import { HuiDrawer } from '@nscode/handy-ui'
基礎用法
用 v-model:visible 控制顯示,title 是標題,內容放在預設插槽裡。預設從右側滑出,點右上角的 ×、點遮罩或按 Esc 都可以關閉。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDrawer, HuiButton } from '@nscode/handy-ui'
const visible = ref(false)
</script>
<template>
<HuiButton type="primary" @click="visible = true">打開抽屜</HuiButton>
<HuiDrawer v-model:visible="visible" title="抽屜標題">
<p>這是抽屜的內容。</p>
</HuiDrawer>
</template>
方向
direction 決定從哪一側滑出:rtl 右側(預設)、ltr 左側、ttb 頂部、btt 底部。點下面的按鈕從對應的一側打開:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDrawer, HuiSpace } from '@nscode/handy-ui'
import type { DrawerDirection } from '@nscode/handy-ui'
const visible = ref(false)
const direction = ref<DrawerDirection>('rtl')
const open = (value: DrawerDirection) => {
direction.value = value
visible.value = true
}
</script>
<template>
<HuiSpace wrap>
<HuiButton @click="open('rtl')">右側(rtl,預設)</HuiButton>
<HuiButton @click="open('ltr')">左側(ltr)</HuiButton>
<HuiButton @click="open('ttb')">頂部(ttb)</HuiButton>
<HuiButton @click="open('btt')">底部(btt)</HuiButton>
</HuiSpace>
<HuiDrawer v-model:visible="visible" :title="`direction:${direction}`" :direction="direction">
<p>從 {{ direction }} 方向滑出。</p>
</HuiDrawer>
</template>
尺寸
size 預設 30%。左右方向的抽屜是寬度,上下方向的抽屜是高度。可以傳數字(按 px 處理)或帶單位的字串。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDrawer, HuiSpace } from '@nscode/handy-ui'
import type { DrawerDirection } from '@nscode/handy-ui'
const visible = ref(false)
const size = ref<string | number>('30%')
const direction = ref<DrawerDirection>('rtl')
const open = (value: string | number, dir: DrawerDirection = 'rtl') => {
size.value = value
direction.value = dir
visible.value = true
}
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<span class="row-label">寬度</span>
<HuiButton @click="open(240)">數字 240(按 px)</HuiButton>
<HuiButton @click="open('30%')">30%(預設)</HuiButton>
<HuiButton @click="open('50%')">50%</HuiButton>
<HuiButton @click="open('480px')">480px</HuiButton>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">高度</span>
<HuiButton @click="open(200, 'btt')">底部 200px</HuiButton>
<HuiButton @click="open('30%', 'btt')">底部 30%(預設)</HuiButton>
<HuiButton @click="open('50%', 'ttb')">頂部 50%</HuiButton>
</HuiSpace>
</HuiSpace>
<HuiDrawer v-model:visible="visible" :title="`size:${size}`" :size="size" :direction="direction">
<p>左右方向的 size 是寬度,上下方向的 size 是高度。</p>
</HuiDrawer>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 40px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
底部按鈕
footer 插槽的內容固定在抽屜底部,靠右排列。內容區比較長時只有內容區捲動,頭部和底部不動。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDrawer, HuiMessage } from '@nscode/handy-ui'
const visible = ref(false)
const save = () => {
visible.value = false
HuiMessage.success('已儲存')
}
</script>
<template>
<HuiButton @click="visible = true">編輯資料</HuiButton>
<HuiDrawer v-model:visible="visible" title="編輯資料" size="360px">
<p v-for="i in 30" :key="i">第 {{ i }} 行表單內容</p>
<template #footer>
<HuiButton @click="visible = false">取消</HuiButton>
<HuiButton type="primary" @click="save">儲存</HuiButton>
</template>
</HuiDrawer>
</template>
內建頁腳
show-footer 顯示內建取消、確定按鈕,預設文字來自語言包。before-confirm 返回 false 或拒絕時不關閉,回傳 Promise 時確定按鈕自動載入,等待期間其他操作不響應;通過後發 confirm,再更新綁定值並發 close('confirm')。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDrawer, HuiButton, HuiMessage } from '@nscode/handy-ui'
const visible = ref(false)
const save = async () => {
await new Promise<void>((resolve) => setTimeout(resolve, 1000))
}
</script>
<template>
<HuiButton type="primary" @click="visible = true">儲存抽屜資料</HuiButton>
<HuiDrawer
v-model:visible="visible"
title="儲存資料"
size="420px"
show-footer
:before-confirm="save"
@confirm="HuiMessage.success('儲存成功')"
@cancel="HuiMessage.info('已取消儲存')"
>
<p>確定後等待一秒完成儲存。</p>
</HuiDrawer>
</template>
配置內建按鈕
文字屬性和空字串優先於語言包。確定按鈕可切換類型,兩個按鈕可單獨隱藏;受控的 confirm-button-loading 只鎖定確定入口,取消仍可操作。
確定按鈕獲得焦點後進入受控載入時,焦點暫時留在面板,載入結束後回到原按鈕;使用者主動移到取消或其他可用控制項時保持該焦點。模板 Drawer 內的內容不會繼承外層函式開啟的 Modal 的 useModalContext()。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDrawer, HuiButton, HuiCheckbox, HuiSelect, HuiSpace } from '@nscode/handy-ui'
import type { ButtonType } from '@nscode/handy-ui'
const visible = ref(false)
const showConfirm = ref(true)
const showCancel = ref(true)
const loading = ref(false)
const type = ref<ButtonType>('primary')
const options = ['primary', 'success', 'warning', 'danger', 'info', 'help', 'default'].map(
(value) => ({ label: value, value })
)
</script>
<template>
<HuiSpace wrap align="center">
<HuiSelect v-model="type" :options="options" style="width: 140px" />
<HuiCheckbox v-model="showConfirm">顯示確定</HuiCheckbox>
<HuiCheckbox v-model="showCancel">顯示取消</HuiCheckbox>
<HuiCheckbox v-model="loading">受控載入</HuiCheckbox>
<HuiButton @click="visible = true">打開配置示例</HuiButton>
</HuiSpace>
<HuiDrawer
v-model:visible="visible"
title="按鈕配置"
size="420px"
show-footer
confirm-button-text="儲存"
cancel-button-text="返回"
:confirm-button-type="type"
:show-confirm-button="showConfirm"
:show-cancel-button="showCancel"
:confirm-button-loading="loading"
>
<p>按鈕狀態由頁面上的配置決定。</p>
</HuiDrawer>
</template>
頁腳作用域
footer 插槽覆蓋內建按鈕,提供 confirm、cancel、confirmLoading,沿用同一套驗證和等待保護;不需要開啟 show-footer。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDrawer, HuiButton, HuiMessage } from '@nscode/handy-ui'
const visible = ref(false)
const save = async () => {
await new Promise<void>((resolve) => setTimeout(resolve, 1000))
}
</script>
<template>
<HuiButton @click="visible = true">自訂抽屜頁腳</HuiButton>
<HuiDrawer
v-model:visible="visible"
title="自訂操作"
size="420px"
:before-confirm="save"
@confirm="HuiMessage.success('已儲存')"
>
<p>自訂按鈕沿用同一套確定和取消流程。</p>
<template #footer="{ confirm, cancel, confirmLoading }">
<HuiButton :disabled="confirmLoading" @click="cancel">返回</HuiButton>
<HuiButton type="success" :loading="confirmLoading" @click="confirm">儲存</HuiButton>
</template>
</HuiDrawer>
</template>
關閉原因
before-close 的參數區分取消、關閉按鈕、遮罩和 Esc。下面取消直接關閉,其他方式先詢問,回傳 Promise 等待期間鎖定入口;外部修改 v-model:visible 不經過掛鉤,close 沒有參數。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDrawer, HuiButton, HuiMessageBox, HuiSpace } from '@nscode/handy-ui'
import type { ModalCloseTrigger } from '@nscode/handy-ui'
const visible = ref(false)
const last = ref('尚未關閉')
const beforeClose = async (trigger: ModalCloseTrigger) => {
if (trigger === 'cancel') return true
try {
await HuiMessageBox.confirm('資料尚未儲存,確定關閉嗎?', '關閉資料')
return true
} catch {
return false
}
}
const onClose = (trigger?: ModalCloseTrigger | 'confirm') => {
last.value = trigger ?? '外部修改 v-model:visible'
}
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiButton @click="visible = true">查看抽屜關閉原因</HuiButton>
<span>最近關閉:{{ last }}</span>
</HuiSpace>
<HuiDrawer
v-model:visible="visible"
title="關閉原因"
size="420px"
show-footer
:before-close="beforeClose"
@close="onClose"
>
<p>可以分別點擊取消、關閉按鈕、遮罩,或按 Esc。</p>
</HuiDrawer>
</template>
自訂頭部和不顯示頭部
header 插槽替換標題,右上角的關閉按鈕還在。with-header 設為 false 時整個頭部(標題和關閉按鈕)都不顯示。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDrawer, HuiIcon, HuiSpace } from '@nscode/handy-ui'
const a = ref(false)
const b = ref(false)
</script>
<template>
<HuiSpace wrap>
<HuiButton @click="a = true">自訂頭部</HuiButton>
<HuiButton @click="b = true">不顯示頭部(with-header=false)</HuiButton>
</HuiSpace>
<HuiDrawer v-model:visible="a" size="360px">
<template #header>
<HuiSpace align="center">
<HuiIcon name="setting" />
<strong>自訂頭部</strong>
</HuiSpace>
</template>
<p>內容</p>
</HuiDrawer>
<HuiDrawer v-model:visible="b" :with-header="false" size="320px">
<p>沒有頭部,自己放一個關閉按鈕。</p>
<HuiButton @click="b = false">關閉</HuiButton>
</HuiDrawer>
</template>
不顯示遮罩
modal 設為 false 時不顯示遮罩,抽屜以外的頁面可以照常點擊。這時點頁面不會關閉抽屜,用 × 或 Esc 關閉。
lockScroll 缺省跟隨 modal;此處無模態時預設不鎖頁面捲動,如需鎖定可顯式設定 :lock-scroll="true"。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDrawer, HuiSpace } from '@nscode/handy-ui'
const visible = ref(false)
const count = ref(0)
</script>
<template>
<HuiSpace wrap>
<HuiButton @click="visible = true">打開沒有遮罩的抽屜</HuiButton>
<HuiButton @click="count++">抽屜打開時也能點({{ count }})</HuiButton>
</HuiSpace>
<HuiDrawer
v-model:visible="visible"
title="沒有遮罩"
size="320px"
:modal="false"
:lock-scroll="false"
>
<p>可以一邊看抽屜,一邊操作頁面。</p>
</HuiDrawer>
</template>
限制關閉方式
三個開關分別控制三種關閉方式,預設都是開的:
close-on-click-modal:點遮罩關閉。close-on-press-escape:按 Esc 關閉。show-close:顯示右上角的關閉按鈕。
三個都關掉以後,只能由你自己把 v-model:visible 的值改成 false 來關閉。下面每個按鈕關掉其中一種,最後一個三種都關掉:
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiButton, HuiDrawer, HuiSpace } from '@nscode/handy-ui'
const visible = ref(false)
const title = ref('')
const options = reactive({
closeOnClickModal: true,
closeOnPressEscape: true,
showClose: true
})
const open = (label: string, next: Partial<typeof options>) => {
Object.assign(options, { closeOnClickModal: true, closeOnPressEscape: true, showClose: true })
Object.assign(options, next)
title.value = label
visible.value = true
}
</script>
<template>
<HuiSpace wrap>
<HuiButton @click="open('按遮罩不關閉', { closeOnClickModal: false })">
點遮罩不關閉(close-on-click-modal)
</HuiButton>
<HuiButton @click="open('按 Esc 不關閉', { closeOnPressEscape: false })">
按 Esc 不關閉(close-on-press-escape)
</HuiButton>
<HuiButton @click="open('沒有關閉按鈕', { showClose: false })">
不顯示關閉按鈕(show-close)
</HuiButton>
<HuiButton
type="primary"
@click="
open('只能按下方按鈕關閉', {
closeOnClickModal: false,
closeOnPressEscape: false,
showClose: false
})
"
>
三個都關掉
</HuiButton>
</HuiSpace>
<HuiDrawer
v-model:visible="visible"
:title="title"
:close-on-click-modal="options.closeOnClickModal"
:close-on-press-escape="options.closeOnPressEscape"
:show-close="options.showClose"
>
<p>點遮罩:{{ options.closeOnClickModal ? '關閉' : '不關閉' }}</p>
<p>按 Esc:{{ options.closeOnPressEscape ? '關閉' : '不關閉' }}</p>
<p>右上角的關閉按鈕:{{ options.showClose ? '顯示' : '不顯示' }}</p>
<template #footer>
<HuiButton type="primary" @click="visible = false">我知道了</HuiButton>
</template>
</HuiDrawer>
</template>
關閉前確認
傳了 before-close 以後,點 ×、點遮罩、按 Esc 時先呼叫這個函式,由它決定關不關。有三種寫法,下面每個按鈕用一種:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiCheckbox, HuiDrawer, HuiMessage, HuiSpace } from '@nscode/handy-ui'
type Mode = 'void' | 'return' | 'promise'
const visible = ref(false)
const saved = ref(false)
const mode = ref<Mode>('void')
// 沒有回傳值同樣放行;等待非同步操作應返回 Promise。
const byVoid = () => {
HuiMessage.info('未回傳值,直接關閉')
}
// 寫法二:返回 true 關閉、返回 false 不關閉
const byReturn = () => {
if (!saved.value) HuiMessage.warning('先勾選“我已儲存”')
return saved.value
}
// 寫法三:返回 Promise,等非同步操作(這裡用定時器模擬儲存)結束再決定
const byPromise = () =>
new Promise<boolean>((resolve) => {
HuiMessage.info('正在儲存,1 秒後關閉')
setTimeout(() => resolve(true), 1000)
})
const handlers = { void: byVoid, return: byReturn, promise: byPromise }
const titles = {
void: '寫法一:返回 undefined',
return: '寫法二:返回布林值',
promise: '寫法三:返回 Promise'
}
const open = (value: Mode) => {
mode.value = value
saved.value = false
visible.value = true
}
</script>
<template>
<HuiSpace wrap>
<HuiButton @click="open('void')">返回 undefined</HuiButton>
<HuiButton @click="open('return')">返回布林值</HuiButton>
<HuiButton @click="open('promise')">返回 Promise</HuiButton>
</HuiSpace>
<HuiDrawer v-model:visible="visible" :title="titles[mode]" :before-close="handlers[mode]">
<HuiCheckbox v-if="mode === 'return'" v-model="saved">我已儲存</HuiCheckbox>
<p v-else>
{{ mode === 'promise' ? '點 × 或按 Esc,1 秒後才關閉。' : '返回 undefined,直接關閉。' }}
</p>
</HuiDrawer>
</template>
具體規則:
- 返回
true(或 Promise 的結果是true):關閉。 - 返回
false:不關閉。 - 沒有回傳值或 Promise resolve
undefined:關閉。 - 函式拋出錯誤,或回傳的 Promise 被拒絕:不關閉。
多層疊加
抽屜裡可以再打開抽屜或對話框。按 Esc 只關閉最後打開的那一個;頁面捲動要等全部關掉才恢復。
浮層按每次打開的先後分配層級:第一個使用最近ConfigProvider或應用配置的zIndex(預設2000),後打開的自動層級高於目前可見層;隱藏後重新整理自動層級,顯式zIndex保留。重開保留原根節點的位置和內部狀態,傳送的下拉、氣泡和固定批量欄按元件樹歸屬於父浮層。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDrawer, HuiModal, HuiSpace } from '@nscode/handy-ui'
const outer = ref(false)
const inner = ref(false)
const dialog = ref(false)
</script>
<template>
<HuiButton @click="outer = true">打開第一層抽屜</HuiButton>
<HuiDrawer v-model:visible="outer" title="第一層抽屜" size="480px">
<HuiSpace wrap>
<HuiButton @click="inner = true">打開第二層抽屜</HuiButton>
<HuiButton @click="dialog = true">打開對話框</HuiButton>
</HuiSpace>
</HuiDrawer>
<HuiDrawer v-model:visible="inner" title="第二層抽屜" size="300px">
<p>按 Esc 只關閉這一層。</p>
</HuiDrawer>
<HuiModal v-model:visible="dialog" title="抽屜上面的對話框" width="360px">
<p>對話框顯示在抽屜上面。</p>
</HuiModal>
</template>
掛載目標
抽屜預設掛到 body,不受元件祖先的 transform、filter、overflow 限制。需要放進指定容器時,append-to 可接收選擇器或已連接到文件的 HTMLElement。每次打開和目標變化時重新解析;目標缺失、選擇器無效或元素已離開文件時,開發環境警告並改掛 body,關閉和卸載仍正常清理。初始就打開時會等待同一模板其他節點掛載,目標可以寫在抽屜元件後面。
浮層按每次打開的先後分配層級:第一個使用最近ConfigProvider或應用配置的zIndex(預設2000),後打開的自動層級高於目前可見層;隱藏後重新整理自動層級,顯式zIndex保留。重開保留原根節點的位置和內部狀態,傳送的下拉、氣泡和固定批量欄按元件樹歸屬於父浮層。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDrawer } from '@nscode/handy-ui'
const visible = ref(false)
</script>
<template>
<HuiButton @click="visible = true">打開抽屜</HuiButton>
<div
id="drawer-mount-point"
style="min-height: 180px; border: 1px dashed var(--hui-border-color);"
>
指定的掛載容器
<HuiDrawer v-model:visible="visible" title="掛到指定容器" append-to="#drawer-mount-point">
<p>關閉後內容仍由元件保留,重新打開繼續顯示。</p>
</HuiDrawer>
</div>
</template>
舊屬性 append-to-body 暫時保留一個版本:false 可繼續原位呈現,true 表示掛到 body。同時傳新舊屬性時 append-to 優先;遷移後請改用 append-to。
預設掛到 body 後,祖先選擇器、父元件 scoped 樣式中的 :deep()、祖先元素覆蓋的 CSS 變數和局部 data-palette 容器不再透過原 DOM 祖先作用於抽屜;原生 <form> 中的欄位掛走後也不再自動屬於原表單。需要暫時保留這些關係時,不傳 append-to 並使用 :append-to-body="false" 保持原位,或顯式掛入相應容器。Vue 的 provide、元件插槽和事件關係仍保留。
事件
v-model:visible 的值變成 true 時觸發 open;關閉時觸發 close,不管是使用者點 ×、點遮罩、按 Esc,還是外部把 v-model:visible 改成 false,每次關閉只觸發一次。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDrawer, HuiMessage } from '@nscode/handy-ui'
const visible = ref(false)
const onOpen = () => {
HuiMessage.info('open:開始打開')
}
const onClose = () => {
HuiMessage.info('close:開始關閉')
}
</script>
<template>
<HuiButton @click="visible = true">打開抽屜</HuiButton>
<HuiDrawer v-model:visible="visible" title="事件" @open="onOpen" @close="onClose">
<p>點 ×、點遮罩、按 Esc 或下面的按鈕關閉,都會觸發 close。</p>
<HuiButton @click="visible = false">改 v-model:visible 關閉</HuiButton>
</HuiDrawer>
</template>
保留內容與關閉後銷毀
切換 destroy-on-close 對比關閉前後的輸入狀態,opened、closed 在動畫結束時更新狀態。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDrawer, HuiButton, HuiSwitch, HuiSpace } from '@nscode/handy-ui'
const visible = ref(false)
const destroy = ref(false)
const status = ref('')
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace align="center"
><HuiButton @click="visible = true">打開抽屜</HuiButton><span>destroy-on-close</span
><HuiSwitch v-model="destroy"
/></HuiSpace>
<p>動畫事件:{{ status }}</p>
<HuiDrawer
v-model:visible="visible"
title="輸入後關閉再打開"
:destroy-on-close="destroy"
@opened="status = 'opened'"
@closed="status = 'closed'"
><input placeholder="輸入內容後關閉再打開"
/></HuiDrawer>
</HuiSpace>
</template>
Props
| 屬性 | 類型 | 預設值 | 說明 |
|---|---|---|---|
| visible | boolean | false | 是否顯示,支援 v-model:visible |
| title | string | '' | 標題。也可以用 header 插槽 |
| direction | 'rtl' | 'ltr' | 'ttb' | 'btt' | 'rtl' | 從哪一側滑出:rtl 右側、ltr 左側、ttb 頂部、btt 底部 |
| size | string | number | '30%' | 抽屜尺寸:左右方向是寬度,上下方向是高度。數字按 px 處理 |
| modal | boolean | true | 是否顯示遮罩。為 false 時抽屜以外的頁面可以操作 |
| appendTo | string | HTMLElement | 'body' | 掛載目標;無效、缺失或離線時回退 body,每次打開重新解析 |
| appendToBody | boolean | - | 已廢棄,保留一個版本;false 原位呈現、true 掛到 body,新屬性優先 |
| lockScroll | boolean | modal 的值 | 不傳時有遮罩鎖頁面捲動、無模態時不鎖;顯式傳值優先 |
| closeOnClickModal | boolean | true | 點遮罩是否關閉 |
| closeOnPressEscape | boolean | true | 按 Esc 是否關閉 |
| showClose | boolean | true | 是否顯示右上角的關閉按鈕 |
| beforeClose | (trigger: ModalCloseTrigger) => boolean | void | Promise<boolean | void> | - | 關閉前驗證,僅 false、拋錯或拒絕時攔截,其餘回傳值放行;Promise 等待期間鎖定其他入口 |
| showFooter | boolean | false | 沒有 footer 插槽時顯示內建頁腳 |
| confirmButtonText | string | 語言包“確定” | 內建確定按鈕文字,空串優先 |
| cancelButtonText | string | 語言包“取消” | 內建取消按鈕文字,空串優先 |
| confirmButtonType | ButtonType | 'primary' | 內建確定按鈕類型 |
| showConfirmButton | boolean | true | 是否顯示內建確定按鈕 |
| showCancelButton | boolean | true | 是否顯示內建取消按鈕 |
| confirmButtonLoading | boolean | false | 受控確定等待狀態,與 beforeConfirm 自動狀態取或 |
| beforeConfirm | () => boolean | void | Promise<boolean | void> | - | 確定前驗證,false 或拒絕保留;等待期間鎖定操作 |
| withHeader | boolean | true | 是否顯示頭部(標題和關閉按鈕) |
| destroyOnClose | boolean | false | 關閉動畫結束後是否銷毀內容,預設保留內容狀態 |
Events
| 事件 | 回呼參數 | 說明 |
|---|---|---|
| update:visible | (value: boolean) | 使用者關閉抽屜或確定通過時觸發,值是 false |
| open | - | 開始打開時觸發,包括初始 visible 為 true 的掛載 |
| close | (trigger?: ModalCloseTrigger | 'confirm') | 先更新 visible,再觸發 close;使用者操作帶原因,外部修改 v-model:visible 沒有參數,每輪只觸發一次 |
| opened | - | 打開動畫結束後觸發 |
| closed | - | 關閉動畫結束後觸發,隨後按 destroyOnClose 銷毀內容 |
| confirm | - | 確定驗證通過後、關閉前觸發 |
| cancel | - | 點擊取消後、執行 beforeClose 前觸發;驗證拒絕也會觸發 |
Slots
| 插槽 | 作用域參數 | 說明 |
|---|---|---|
| default | - | 抽屜的內容 |
| header | - | 頭部內容,替換 title。關閉按鈕不受影響 |
| footer | { confirm, cancel, confirmLoading } | 自訂操作區,覆蓋內建頁腳;函式沿用內建驗證與等待流程 |
方法
通過 v-model:visible 控制顯示,內建頁腳與作用域插槽按上面的確認、取消流程關閉。
類型
import type {
DrawerDirection,
DrawerProps,
DrawerEmits,
DrawerFooterSlotProps,
ModalCloseTrigger
} from '@nscode/handy-ui'
type DrawerDirection = 'rtl' | 'ltr' | 'ttb' | 'btt'
type ModalCloseTrigger = 'close-button' | 'mask' | 'escape' | 'cancel'
interface DrawerFooterSlotProps {
confirm: () => void
cancel: () => void
confirmLoading: boolean
}