Skip to content

FaButton ​

Wraps Element Plus Button with automatic loading, a page overlay and the exposed doLoading method.

Button States

Interactive example
View code
Vue
<template>
	<div class="demo-stack">
		<div class="demo-row">
			<FaButton type="primary" @click="handleAsyncClick">自动 Loading</FaButton>
			<FaButton ref="buttonRef" type="success" disabled-loading @click="handleExposeLoading">Expose Loading</FaButton>
			<FaButton type="warning" plain disabled-loading>禁用自动 Loading</FaButton>
			<FaButton type="danger" disabled>禁用状态</FaButton>
		</div>
		<div class="demo-row">
			<FaButton size="small" round disabled-loading>小型圆角</FaButton>
			<FaButton type="primary" dashed disabled-loading>虚线按钮</FaButton>
			<FaButton type="primary" link disabled-loading>链接按钮</FaButton>
			<FaButton type="primary" circle icon="el-icon-Search" disabled-loading />
		</div>
	</div>
</template>

<script setup lang="ts">
import { useTemplateRef } from "vue";
import { ElMessage } from "element-plus";

const buttonRef = useTemplateRef<{ doLoading: (callback: () => void | Promise<void>) => Promise<void> }>("buttonRef");

const handleAsyncClick = (_event: MouseEvent, done?: () => void): void => {
	window.setTimeout(() => {
		ElMessage.success("异步操作完成");
		done?.();
	}, 700);
};

const handleExposeLoading = (): void => {
	buttonRef.value?.doLoading(async () => {
		await new Promise<void>((resolve) => {
			window.setTimeout(resolve, 800);
		});
		ElMessage.success("Expose Loading 完成");
	});
};
</script>

FaButton Complete API

Props

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

PropertySourceDescriptionTypeDefault
loadingFast overrideLoading state.BooleanFastfalseELfalse
loadingIconFast overrideLoading icon component.String / Object / FunctionFast—EL—
disabledLoadingFast additionDisable automatic Fast loading on click.Booleanfalse
sizeEL nativeComponent size.String—
disabledEL nativeDisable the component or current option.Booleanfalse
typeEL nativeButton visual type.String""
iconEL nativeIcon component or name.String / Object / Function—
nativeTypeEL nativeNative button type.Stringbutton
plainEL nativeUse a plain button.Booleanfalse
textEL nativeUse a text button.Booleanfalse
linkEL nativeRender a table cell as a link.Booleanfalse
bgEL nativeShow a background on text buttons.Booleanfalse
autofocusEL nativeAutomatically focus.Booleanfalse
roundEL nativeUse a rounded button.Booleanfalse
circleEL nativeUse a circular button.Booleanfalse
dashedEL nativeUse a dashed button.Booleanfalse
colorEL nativeCustom button color.String—
darkEL nativeUse dark mode for the custom color.Booleanfalse
autoInsertSpaceEL nativeInsert spacing between two Chinese characters.Booleanfalse
tagEL nativeRender the cell as a tag.String / Objectbutton

Events

NameSourceDescriptionParameters / type
clickEL nativeClick event.—

Slots

NameSourceDescriptionParameters / type
defaultEL nativeDefault component content.—
loadingEL nativeCustom loading content.—
iconEL nativeCustom button/component icon.—

Exposes

NameSourceDescriptionParameters / type
refEL nativeUnderlying Element Plus component ref.—
sizeEL nativeResolved button size.—
typeEL nativeResolved button type.—
disabledEL nativeCurrent button disabled state.—
shouldAddSpaceEL nativeWhether the button inserts spacing between two Chinese characters.—
loadingFast additionFast business loading state.—
doLoading(function)Fast additionRuns a sync/async function with shared loading and overlay state.(function)

FaButton instance methods ​

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

doLoading Loading ​

Runs a task with button loading state.

Signature ​

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

Example ​

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

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

const componentRef = ref<InstanceType<typeof FaButton>>();
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.

State and lifecycle ​

Concurrent doLoading calls and click done callbacks own separate Loading entries. Duplicate/late completion releases only its owner. External and manually set loading do not close active tasks. Unmount releases this instance and prevents new work.