Skip to content

FaDialog ​

Extends ElDialog with dragging, fullscreen, refresh, a footer and asynchronous business loading. Exposed open(function?) and close(function?) methods execute business hooks and return a Promise. v-model only receives internal state updates; assigning it externally does not open or close the dialog. Fast open and close events signal completed business flows, while opened and closed retain the Element Plus animation lifecycle. The caller controls width at every breakpoint.

Basic

Interactive example
View code
Vue
<template>
	<div class="demo-row">
		<ElButton type="primary" @click="dialogRef?.open(wait)">打开 Dialog</ElButton>
	</div>

	<FaDialog ref="dialogRef" title="编辑项目" :before-close="wait" @confirm-click="confirmDialog">
		<template #default="{ loading }">
			<ElAlert :closable="false" :title="loading ? '正在执行业务钩子…' : '内容已就绪'" type="success" />
		</template>
	</FaDialog>
</template>

<script setup lang="ts">
import { useTemplateRef } from "vue";

interface ContainerExpose {
	close: (callback?: () => void | Promise<void>) => Promise<void>;
	open: (callback?: () => void | Promise<void>) => Promise<void>;
}

const dialogRef = useTemplateRef<ContainerExpose>("dialogRef");

const wait = async (): Promise<void> => {
	await new Promise<void>((resolve) => {
		window.setTimeout(resolve, 600);
	});
};

const confirmDialog = (): void => {
	dialogRef.value?.close(wait);
};
</script>

Lifecycle

Interactive example
View code
Vue
<template>
	<div class="demo-stack">
		<ElButton type="primary" @click="dialogRef?.open()">观察事件时序</ElButton>
		<div class="demo-log">
			<div v-for="item in logs" :key="item">{{ item }}</div>
			<span v-if="logs.length === 0">尚无事件</span>
		</div>
	</div>
	<FaDialog
		ref="dialogRef"
		title="异步生命周期"
		:after-open="waitOpen"
		:before-close="waitClose"
		@open="append('Fast open 事件')"
		@opened="append('Element opened 动画事件')"
		@close="append('Fast close 事件')"
		@closed="append('Element closed 动画事件')"
		@confirm-click="dialogRef?.close(waitClose)"
	>
		<template #default="{ loading }">{{ loading ? "等待业务钩子" : "业务内容已可操作" }}</template>
	</FaDialog>
</template>

<script setup lang="ts">
import { ref, useTemplateRef } from "vue";

interface DialogExpose {
	close: (callback?: () => void | Promise<void>) => Promise<void>;
	open: () => Promise<void>;
}

const dialogRef = useTemplateRef<DialogExpose>("dialogRef");
const logs = ref<string[]>([]);
const append = (message: string): void => {
	logs.value.unshift(`${new Date().toLocaleTimeString()} ${message}`);
};
const waitOpen = async (): Promise<void> => {
	append("afterOpen 开始");
	await new Promise<void>((resolve) => {
		window.setTimeout(resolve, 500);
	});
	append("afterOpen 完成");
};
const waitClose = async (): Promise<void> => {
	append("beforeClose 开始");
	await new Promise<void>((resolve) => {
		window.setTimeout(resolve, 500);
	});
	append("beforeClose 完成");
};
</script>

Dialog Features

Interactive example
View code
Vue
<template>
	<ElButton type="primary" @click="dialogRef?.open(load)">通过 Expose 打开</ElButton>
	<FaDialog ref="dialogRef" title="完整功能 Dialog" full-height style="--height: 72%" width="72%" show-before-close>
		<template #header><ElTag size="small">自定义 Header</ElTag></template>
		<template #default="{ loading }">
			<div class="demo-stack">
				<ElAlert :closable="false" :title="loading ? '业务处理中…' : '内容已就绪'" type="success" />
				<ElButton @click="dialogRef?.doLoading(load)">运行局部异步任务</ElButton>
			</div>
		</template>
		<template #footer="{ close }"><ElButton @click="close">插槽关闭</ElButton></template>
	</FaDialog>
</template>

<script setup lang="ts">
import { useTemplateRef } from "vue";

interface DialogExpose {
	close: (callback?: () => void | Promise<void>) => Promise<void>;
	doLoading: (callback: () => void | Promise<void>) => Promise<void>;
	open: (callback?: () => void | Promise<void>) => Promise<void>;
}

const dialogRef = useTemplateRef<DialogExpose>("dialogRef");
const load = async (): Promise<void> => {
	await new Promise<void>((resolve) => {
		window.setTimeout(resolve, 500);
	});
};
</script>

FaDialog Complete API

Props

EL defaults refer to Element Plus before Fast is imported. 2.14.7

PropertySourceDescriptionTypeDefault
alignCenterFast overrideVertically center the dialog.BooleanFasttrueELfalse
draggableFast global enhancementAllow dragging.BooleanFasttrueELfalse
overflowFast overrideAllow dragging the dialog beyond the viewport.BooleanFasttrueELfalse
appendToBodyFast overrideAppend to body.BooleanFasttrueELfalse
beforeCloseFast overrideCallback before closing.FunctionFast—EL—
destroyOnCloseFast overrideDestroy overlay content after closing.BooleanFasttrueELfalse
topFast overrideDialog offset from the page top.StringFast5vhEL—
modelValueFast overridev-model value.BooleanFastfalseELfalse
widthFast overrideComponent width.String / NumberFast90%EL—
showRefreshFast additionShow refresh button.Booleantrue
showFullscreenFast additionShow fullscreen button.Booleantrue
showCloseButtonFast additionShow footer close button.Booleantrue
showConfirmButtonFast additionShow footer confirm button.Booleantrue
disabledConfirmButtonFast additionDisable the Fast footer confirm button.Booleanfalse
closeButtonTextFast additionFooter close-button label.String取消
confirmButtonTextFast additionFooter confirm-button label.String确认
hideFooterFast additionHide footer actions.Booleanfalse
fullHeightFast additionFill available height with dialog content.Booleanfalse
showBeforeCloseFast additionShow the team confirmation before closing.Booleanfalse
afterOpenFast additionFast opening hook; supports async functions.Function—
centerEL nativeHorizontally center dialog header/footer content.Booleanfalse
closeIconEL nativeClose-button icon.String / Object / Function—
fullscreenEL nativeFill the viewport with the dialog.Booleanfalse
headerClassEL nativecustom class names for header wrapperString / Array / Object / Booleanfalse
bodyClassEL nativecustom class names for body wrapperString / Array / Object / Booleanfalse
footerClassEL nativecustom class names for footer wrapperString / Array / Object / Booleanfalse
showCloseEL nativewhether to show a close buttonBooleantrue
titleEL nativeComponent title.String""
ariaLevelEL nativeOverlay heading level in the accessibility tree.String2
appendToEL nativeOverlay mount target.String / Objectbody
closeOnClickModalEL nativewhether the Dialog can be closed by clicking the maskBooleantrue
closeOnPressEscapeEL nativewhether the Dialog can be closed by pressing ESCBooleantrue
lockScrollEL nativewhether scroll of body is disabled while Dialog is displayedBooleantrue
modalEL nativewhether a mask is displayedBooleantrue
modalPenetrableEL nativewhether the mask is penetrable. The modal attribute must be false.Booleanfalse
openDelayEL nativethe Time(milliseconds) before openNumber0
closeDelayEL nativethe Time(milliseconds) before closeNumber0
modalClassEL nativecustom class names for maskString / Array / Object / Booleanfalse
zIndexEL nativesame as z-index in native CSS, z-order of dialogNumber—
trapFocusEL nativeTrap keyboard focus inside the open overlay.Booleanfalse
headerAriaLevelEL nativeheader's aria-level attributeString2
transitionEL nativeOverlay opening/closing transition name.String / Object—

Events

NameSourceDescriptionParameters / type
openEL nativeFast opening business flow completes.—
openedEL nativeOpening animation completes.—
closeEL nativeClosing flow completes.—
closedEL nativeClosing animation completes.—
update:modelValueEL nativeUpdates v-model.—
openAutoFocusEL nativeOverlay opens and autofocus completes.—
closeAutoFocusEL nativeOverlay closes and focus restoration completes.—
confirmClickFast additionFast confirm-button click.—

Slots

NameSourceDescriptionParameters / type
default({ loading })EL nativeDefault component content.({ loading })
header({ loading, close })EL nativeCustom header or table-header business content.({ loading, close })
titleEL nativeCustom dialog/drawer title.—
footer({ loading, close })EL nativeCustom footer actions; overlays provide loading and close.({ loading, close })

Exposes

NameSourceDescriptionParameters / type
handleCloseEL nativeInvokes Element Plus internal closing behavior.—
dialogContentRefEL nativeElDialog internal content ref.—
resetPositionEL nativeRestores the initial dialog position.—
loadingFast additionFast business loading state.—
visibleFast additionCurrent overlay/context-menu visibility.—
openFast additionRuns the Fast asynchronous opening flow.—
closeFast additionRuns the Fast asynchronous closing flow.—
refreshFast additionRepeats the data request or refreshes business content.—
doLoadingFast additionRuns a sync/async function with shared loading and overlay state.—

FaDialog instance methods ​

These are call snippets. Use rows, options and fields from your actual data.

handleClose Close ​

Runs native closing behavior and beforeClose.

Signature ​

ts
handleClose(): void;

Example ​

vue
<template>
	<FaDialog ref="componentRef" />
	<button type="button" @click="handleExample">Call method</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDialog } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDialog>>();
function handleExample() {
	componentRef.value?.handleClose();
}
</script>

Input: No parameters.

Returns: void.

resetPosition Position ​

Resets the position.

Signature ​

ts
resetPosition(): void;

Example ​

vue
<template>
	<FaDialog ref="componentRef" />
	<button type="button" @click="handleExample">Call method</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDialog } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDialog>>();
function handleExample() {
	componentRef.value?.resetPosition();
}
</script>

Input: No parameters.

Returns: void.

open Open ​

Opens the dialog.

Signature ​

ts
open(openFunction?: () => void | Promise<void>): Promise<void>;

Example ​

vue
<template>
	<FaDialog ref="componentRef" />
	<button type="button" @click="handleExample">Call method</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDialog } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDialog>>();
const saveData = async () => Promise.resolve();
async function handleExample() {
	const result = await componentRef.value?.open(async () => saveData());
	console.log(result);
}
</script>

Input ​

InputTypeRequired / defaultDescription
openFunction(() => void | Promise<void>) | undefinedOptionalOptional synchronous/asynchronous task before the opening animation.

Returns ​

ValueTypeDescription
resultPromise<void>Asynchronous result; callers handle Promise rejection.

close Close ​

Closes the dialog.

Signature ​

ts
close(closeFunction?: () => void | Promise<void>): Promise<void>;

Example ​

vue
<template>
	<FaDialog ref="componentRef" />
	<button type="button" @click="handleExample">Call method</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDialog } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDialog>>();
const saveData = async () => Promise.resolve();
async function handleExample() {
	const result = await componentRef.value?.close(async () => saveData());
	console.log(result);
}
</script>

Input ​

InputTypeRequired / defaultDescription
closeFunction(() => void | Promise<void>) | undefinedOptionalOptional synchronous/asynchronous task before the closing animation.

Returns ​

ValueTypeDescription
resultPromise<void>Asynchronous result; callers handle Promise rejection.

refresh Refresh ​

Refreshes the dialog.

Signature ​

ts
refresh(): Promise<void>;

Example ​

vue
<template>
	<FaDialog ref="componentRef" />
	<button type="button" @click="handleExample">Call method</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDialog } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDialog>>();
async function handleExample() {
	const result = await componentRef.value?.refresh();
	console.log(result);
}
</script>

Input ​

This method has no input parameters.

Returns ​

ValueTypeDescription
resultPromise<void>Asynchronous result; callers handle Promise rejection.

doLoading Loading ​

Runs a task with dialog loading state.

Signature ​

ts
doLoading(loadingFunction: () => void | Promise<void>): Promise<void>;

Example ​

vue
<template>
	<FaDialog ref="componentRef" />
	<button type="button" @click="handleExample">Call method</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDialog } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDialog>>();
const saveData = async () => Promise.resolve();
async function handleExample() {
	const result = await componentRef.value?.doLoading(async () => saveData());
	console.log(result);
}
</script>

Input ​

InputTypeRequired / defaultDescription
loadingFunction() => void | Promise<void>RequiredSynchronous or asynchronous task to run while loading.

Returns ​

ValueTypeDescription
resultPromise<void>Asynchronous result; callers handle Promise rejection.