Skip to content

FaContextMenu ​

Call the exposed open({ x, y }) method to open the menu at pointer coordinates. Items support icons, visibility, disabled state, callbacks and a shared click event.

Context Menu

Interactive example
View code
Vue
<template>
	<div class="demo-context-target" @contextmenu="openMenu">在此区域单击鼠标右键</div>
	<FaContextMenu ref="menuRef" :data="data" />
</template>

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

interface ContextMenuExpose {
	open: (axis: { x: number; y: number }) => void;
}

const menuRef = useTemplateRef<ContextMenuExpose>("menuRef");
const data = [
	{
		name: "refresh",
		label: "刷新",
		icon: "el-icon-Refresh",
		click: () => {
			ElMessage.success("已刷新");
		},
	},
	{ name: "edit", label: "编辑", icon: "el-icon-Edit" },
	{ name: "locked", label: "禁用项", icon: "el-icon-Lock", disabled: true },
	{ name: "hidden", label: "隐藏项", hide: true },
];
const openMenu = (event: MouseEvent): void => {
	event.preventDefault();
	menuRef.value?.open({ x: event.clientX, y: event.clientY });
};
</script>

FaContextMenu Complete API

Props

PropertySourceDescriptionTypeDefault
dataFast additionComponent data.Array[]

Events

NameSourceDescriptionParameters / type
clickFast additionClick event.—

Exposes

NameSourceDescriptionParameters / type
visibleFast additionCurrent overlay/context-menu visibility.—
open({ x, y })Fast additionRuns the Fast asynchronous opening flow.({ x, y })
close()Fast additionRuns the Fast asynchronous closing flow.()

FaContextMenu instance methods ​

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

open Open ​

Opens the menu.

Signature ​

ts
open(axis?: { x: number; y: number; }): void;

Example ​

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

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

const componentRef = ref<InstanceType<typeof FaContextMenu>>();
function handleExample() {
	componentRef.value?.open({ x: 120, y: 80 });
}
</script>

Input ​

InputTypeRequired / defaultDescription
axis{ x: number; y: number; }OptionalViewport-relative x/y coordinates; defaults to { x: 0, y: 0 }.

Returns ​

ValueTypeDescription
resultvoidNo return value.

close Close ​

Closes the menu.

Signature ​

ts
close(): void;

Example ​

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

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

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

Input: No parameters.

Returns: void.