<VueFlow />
The <VueFlow /> component is the heart of your Vue Flow application.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { VueFlow, type Node, type Edge } from '@xyflow/vue';
import '@xyflow/vue/style.css';
const nodes = shallowRef<Node[]>([
{ id: 'a', data: { label: 'node a' }, position: { x: 0, y: 0 } },
{ id: 'b', data: { label: 'node b' }, position: { x: 0, y: 100 } }
]);
const edges = shallowRef<Edge[]>([
{ id: 'e1-2', source: 'a', target: 'b' }
]);
</script>
<template>
<VueFlow v-model:nodes="nodes" v-model:edges="edges" fit-view />
</template>This component takes a lot of different props, most of which are optional. We’ve tried to document them in groups that make sense to help you find your way.
Common props
These are the props you will most commonly use when working with Vue Flow.
| Name | Type | Default |
|---|---|---|
id | stringAn optional id for the flow. Useful when you render multiple flows on one page. | |
nodes | Node<Record<string, unknown>, string | undefined>[]An array of nodes to render in a controlled flow. | [] |
edges | Edge<Record<string, unknown>, string>[]An array of edges to render in a controlled flow. | [] |
edgeTypes | EdgeTypesObject<Edge<Record<string, unknown>, string>>Custom edge types to be available in a flow. Vue Flow matches an edge’s type to a component in
the | |
nodeTypes | NodeTypesObject<Node<Record<string, unknown>, string | undefined>>Custom node types to be available in a flow. Vue Flow matches a node’s type to a component in
the | |
forceColorMode | ColorModeForces a color scheme on the flow container via class name, overriding the system default.
Page-level theming is typically done by setting | |
proOptions | ProOptionsBy default, we render a small attribution in the corner of your flows that links back to the project. Anyone is free to remove this attribution whether they’re a Pro subscriber or not but we ask that you take a quick look at our https://vueflow.dev/learn/troubleshooting/remove-attribution removing attribution guide before doing so. | |
ariaLabelConfig | Partial<AriaLabelConfig$1>Customize the aria labels / a11y descriptions (node/edge descriptions, the aria-live move message, and the Controls/MiniMap/Handle labels). Merged over the defaults. | |
debug | booleanWhen | false |
...props | HTMLAttributes |
Viewport props
| Name | Type | Default |
|---|---|---|
defaultViewport | Partial<Viewport$1>Sets the initial position and zoom of the viewport. If a default viewport is provided but | { x: 0, y: 0, zoom: 1 } |
fitView | booleanWhen | |
fitViewOptions | {
padding?: Padding;
includeHiddenNodes?: boolean;
minZoom?: number;
maxZoom?: number;
duration?: number;
ease?: (t: number) => number;
interpolate?: 'smooth' | 'linear';
nodes?: (NodeType | {
id: string;
})[];
}When you typically call | { padding: '5%' } |
minZoom | numberMinimum zoom level. | 0.5 |
maxZoom | numberMaximum zoom level. | 2 |
snapGrid | SnapGridIf | |
onlyRenderVisibleElements | booleanYou can enable this optimisation to instruct Vue Flow to only render nodes and edges that would be visible in the viewport. This might improve performance when you have a large number of nodes and edges but also adds an overhead. | false |
translateExtent | CoordinateExtentBy default, the viewport extends infinitely. You can use this prop to set a boundary. The first pair of coordinates is the top left boundary and the second pair is the bottom right. | [[-∞, -∞], [+∞, +∞]] |
preventScrolling | booleanDisabling this prop will allow the user to scroll the page even when their pointer is over the flow. | true |
attributionPosition | PanelPositionSet position of the attribution | 'bottom-right' |
viewport | ViewportControlled viewport ( |
Node props
| Name | Type | Default |
|---|---|---|
nodeOrigin | NodeOriginThe origin of the node to use when placing it in the flow or looking up its | [0, 0] |
nodesDraggable | booleanControls whether all nodes should be draggable or not. Individual nodes can override this setting
by setting their | true |
nodesConnectable | booleanControls whether all nodes should be connectable or not. Individual nodes can override this
setting by setting their | true |
nodesFocusable | booleanWhen | true |
nodeDragThreshold | numberWith a threshold greater than zero you can delay node drag events. If threshold equals 1, you need to drag the node 1 pixel before a drag event is fired. | 1 |
nodeExtent | CoordinateExtentBy default, nodes can be placed on an infinite flow. You can use this prop to set a boundary. The first pair of coordinates is the top left boundary and the second pair is the bottom right. | |
elevateNodesOnSelect | booleanEnabling this option will raise the z-index of nodes when they are selected. | true |
Edge props
| Name | Type | Default |
|---|---|---|
edgesFocusable | booleanWhen | true |
edgesReconnectable | EdgeReconnectableWhether edges can be updated once they are created. When both this prop is | true |
reconnectRadius | numberThe radius around an edge connection that can trigger an edge reconnection. | 10 |
elevateEdgesOnSelect | booleanEnabling this option will raise the z-index of edges when they are selected. | false |
defaultMarkerColor | string | nullColor of edge markers. You can pass | '#b1b1b7' |
defaultEdgeOptions | DefaultEdgeOptionsDefaults to be applied to all new edges that are added to the flow. Properties on a new edge will
override these defaults if they exist. Does not apply to the |
Event handlers
General Events
| Name | Type | Default |
|---|---|---|
init | [paneEvent: VueFlowInstance<Node<Record<string, unknown>, string | undefined>, Edge<Record<string, unknown>, string>>] | |
error | [error: VueFlowError<ErrorCode, [] | [id?: string | undefined] | [id: string | null] | [id: string, parentId: string] | [type: string] | [id: string] | [id: string] | [id: string] | [id: string] | [id: string, source: string] | [id: string, target: string] | [type: ...] | [id: ...] | [id: ...]>] | |
nodesChange | NodeChangeset<Node<Record<string, unknown>, string | undefined>> | |
edgesChange | EdgeChangeset<Edge<Record<string, unknown>, string>> | |
delete | [event: { nodes: Node<Record<string, unknown>, string | undefined>[]; edges: Edge<Record<string, unknown>, string>[]; }] | |
nodesDelete | [nodes: Node<Record<string, unknown>, string | undefined>[]] | |
edgesDelete | [edges: Edge<Record<string, unknown>, string>[]] | |
onBeforeDelete | OnBeforeDelete<Node<Record<string, unknown>, string | undefined>, Edge<Record<string, unknown>, string>> | nullThis handler is called before nodes or edges are deleted, allowing the deletion to be aborted by
returning | |
updateNodeInternals | [] |
Viewport Events
| Name | Type | Default |
|---|---|---|
moveStart | [moveEvent: { event: MouseTouchEvent | null; viewport: Viewport; }] | |
move | [moveEvent: { event: MouseTouchEvent | null; viewport: Viewport; }] | |
moveEnd | [moveEvent: { event: MouseTouchEvent | null; viewport: Viewport; }] | |
viewportChangeStart | [viewport: Viewport] | |
viewportChange | [viewport: Viewport] | |
viewportChangeEnd | [viewport: Viewport] |
Node Events
| Name | Type | Default |
|---|---|---|
nodeClick | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
nodeDoubleClick | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
nodeMouseEnter | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
nodeMouseMove | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
nodeMouseLeave | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
nodeContextMenu | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
nodeDragStart | [nodeDragEvent: NodeDragEvent<Node<Record<string, unknown>, string | undefined>>] | |
nodeDrag | [nodeDragEvent: NodeDragEvent<Node<Record<string, unknown>, string | undefined>>] | |
nodeDragStop | [nodeDragEvent: NodeDragEvent<Node<Record<string, unknown>, string | undefined>>] | |
nodesInitialized | [nodes: Node<Record<string, unknown>, string | undefined>[]] | |
miniMapNodeClick | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
miniMapNodeDoubleClick | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
miniMapNodeMouseEnter | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
miniMapNodeMouseMove | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] | |
miniMapNodeMouseLeave | [nodeMouseEvent: NodeMouseEvent<Node<Record<string, unknown>, string | undefined>>] |
Edge Events
| Name | Type | Default |
|---|---|---|
edgeContextMenu | [edgeMouseEvent: EdgeMouseEvent<Edge<Record<string, unknown>, string>>] | |
edgeMouseEnter | [edgeMouseEvent: EdgeMouseEvent<Edge<Record<string, unknown>, string>>] | |
edgeMouseMove | [edgeMouseEvent: EdgeMouseEvent<Edge<Record<string, unknown>, string>>] | |
edgeMouseLeave | [edgeMouseEvent: EdgeMouseEvent<Edge<Record<string, unknown>, string>>] | |
edgeDoubleClick | [edgeMouseEvent: EdgeMouseEvent<Edge<Record<string, unknown>, string>>] | |
edgeClick | [edgeMouseEvent: EdgeMouseEvent<Edge<Record<string, unknown>, string>>] | |
reconnectStart | [edgeReconnectEvent: EdgeReconnectStartEvent<Edge<Record<string, unknown>, string>>] | |
reconnect | [reconnectEvent: EdgeReconnectEvent<Edge<Record<string, unknown>, string>>] | |
reconnectEnd | [edgeReconnectEvent: EdgeReconnectEndEvent<Node<Record<string, unknown>, string | undefined>, Edge<Record<string, unknown>, string>>] |
Selection Events
| Name | Type | Default |
|---|---|---|
selectionChange | [selectionEvent: SelectionChangeEvent<Node<Record<string, unknown>, string | undefined>, Edge<Record<string, unknown>, string>>] | |
selectionContextMenu | [selectionEvent: { event: MouseEvent; nodes: Node<Record<string, unknown>, string | undefined>[]; }] | |
selectionDragStart | [selectionEvent: NodeDragEvent<Node<Record<string, unknown>, string | undefined>>] | |
selectionDrag | [selectionEvent: NodeDragEvent<Node<Record<string, unknown>, string | undefined>>] | |
selectionDragStop | [selectionEvent: NodeDragEvent<Node<Record<string, unknown>, string | undefined>>] | |
selectionStart | [selectionEvent: MouseEvent] | |
selectionEnd | [selectionEvent: MouseEvent] |
Pane Events
| Name | Type | Default |
|---|---|---|
paneClick | [paneEvent: MouseEvent] | |
paneContextMenu | [paneEvent: MouseEvent] | |
paneMouseEnter | [paneEvent: MouseEvent] | |
paneMouseMove | [paneEvent: MouseEvent] | |
paneMouseLeave | [paneEvent: MouseEvent] | |
paneScroll | [paneEvent: WheelEvent | undefined] |
Connection Events
| Name | Type | Default |
|---|---|---|
connect | [connectionEvent: Connection] | |
connectStart | [connectionEvent: { event?: MouseEvent; } & OnConnectStartParams] | |
connectEnd | [connectionEvent: ConnectEndEvent<Node<Record<string, unknown>, string | undefined>>] | |
isValidConnection | IsValidConnection | nullThis callback can be used to validate a new connection. If you return | |
clickConnectStart | [connectionEvent: { event?: MouseEvent; } & OnConnectStartParams] | |
clickConnectEnd | [connectionEvent: ConnectEndEvent<Node<Record<string, unknown>, string | undefined>>] |
Connection line props
| Name | Type | Default |
|---|---|---|
connectionRadius | numberThe radius around a handle where you drop a connection line to create a new edge. | 20 |
connectionDragThreshold | numberThe threshold in pixels that the pointer must move before a connection line starts to drag. This is useful to prevent accidental connections when clicking on a handle. | 1 |
connectionLineType | ConnectionLineTypeThe path shape drawn while dragging a new connection, see ConnectionLineType . Edges can be of any type once created, but the connection line has to know which path to draw before that. | 'default' |
connectionLineStyle | CSSPropertiesInline style applied to the connection line itself. | |
connectionLineContainerStyle | CSSPropertiesInline style applied to the | |
connectionLineClass | ClassValueAdditional class names applied to the connection line. | |
connectionLineMarkerStart | EdgeMarkerTypeMarker rendered at the start (source handle) of the connection line. | |
connectionLineMarkerEnd | EdgeMarkerTypeMarker rendered at the end (pointer side) of the connection line. |
Interaction props
| Name | Type | Default |
|---|---|---|
elementsSelectable | booleanWhen | true |
autoPanOnConnect | booleanWhen | true |
autoPanOnNodeDrag | booleanWhen | true |
autoPanOnSelection | booleanPan the viewport automatically when the cursor reaches the edge of the viewport while dragging a selection box. | true |
autoPanOnNodeFocus | booleanPan the viewport to a node when it receives keyboard focus (Tab) and isn’t currently within the viewport — keeps keyboard navigation from landing on off-screen nodes. | true |
autoPanSpeed | numberThe speed at which the viewport pans while dragging a node or a selection box. | 15 |
selectNodesOnDrag | booleanIf | true |
panOnDrag | boolean | number[]Enabling this prop allows users to pan the viewport by clicking and dragging. You can also set this prop to an array of numbers to limit which mouse buttons can activate panning. | true |
selectionOnDrag | booleanDraw a selection box on a plain pane drag (no key held). Pair it with | false |
selectionMode | SelectionModeWhen set to | 'full' |
panOnScroll | booleanControls if the viewport should pan by scrolling inside the container. Can be limited to a
specific direction with | false |
panOnScrollMode | PanOnScrollModeThis prop is used to limit the direction of panning when | "free" |
panOnScrollSpeed | numberControls how fast viewport should be panned on scroll. Use together with | 0.5 |
zoomOnScroll | booleanControls if the viewport should zoom by scrolling inside the container. | true |
zoomOnPinch | booleanControls if the viewport should zoom by pinching on a touch screen. | true |
zoomOnDoubleClick | booleanControls if the viewport should zoom by double-clicking somewhere on the flow. | true |
connectionMode | ConnectionModeA loose connection mode will allow you to connect handles with differing types, including source-to-source connections. However, it does not support target-to-target connections. Strict mode allows only connections between source handles and target handles. | 'strict' |
connectOnClick | booleanThe | true |
snapToGrid | booleanWhen enabled, nodes will snap to the grid when dragged. | |
paneDragThreshold | numberDistance in pixels the pointer has to move before dragging the pane starts panning or a selection.
If the pointer moves less, the gesture is treated as a click: | 1 |
zIndexMode | ZIndexModecontrols how the z-index of nodes and edges is calculated.
|
Keyboard props
Style props
Applying certain classes to elements rendered inside the canvas will change how interactions are handled. These props let you configure those class names if you need to.
Notes
- The props of this component get exported as
VueFlowPropsand its events asVueFlowEmits. - With
v-model:nodes/v-model:edgesVue Flow applies node and edge changes for you. With a one-way:nodes/:edgesbinding the flow is controlled: handle@nodes-change/@edges-changeand apply theNodeChangeset/EdgeChangesetyourself.