--- title: Edges --- # Introduction to Edges Edges are the links connecting your nodes, forming a map. Each edge runs from one handle to another, and can be customized to your liking. Remember, every edge is unique and thus **requires a unique id**, a source and target node id. For the full list of options available for an edge, check out the [Edge Type](/typedocs/type-aliases/Edge). ## Adding Edges to the Graph Edges are rendered by passing them to the `edges` prop (or the deprecated `v-model` prop) of the Vue Flow component. :::warning This method will *not* create a change. Check out the [Controlled Flow](/guide/controlled-flow.html) section for more information. ::: :::code-group ```vue [] ``` ```vue [] ``` ::: If you are working with more complex graphs or simply require access to the internal state, the [useVueFlow](/typedocs/functions/useVueFlow) composable will come in handy. The [`addEdges`](/typedocs/interfaces/Actions#addEdges) action is available through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to add edges straight to the state. What's more, this action isn't limited to the component rendering the graph; it can be utilized elsewhere, like in a Sidebar or Toolbar. ```vue ``` ## Removing Edges from the Graph Similar to adding edges, edges can be removed from the graph by removing them from the `mode-value` (using `v-model`) or from the `edges` prop of the Vue Flow component. ```vue ``` The [`removeEdges`](/typedocs/interfaces/Actions#removeEdges) action is available through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to remove edges straight from the state. You can also use this action outside the component rendering the graph, like in a Sidebar or Toolbar. ```vue ``` ## Updating Edge Data Since edges are reactive object, you can update their data at any point by simply mutating it. This allows you to change the label, or even add new properties to the data object at any point in time. There are multiple ways of achieving this, here are some examples: ::: code-group ```ts [useVueFlow] import { useVueFlow } from '@vue-flow/core' const instance = useVueFlow() // use the `updateEdgeData` method to update the data of an edge instance.updateEdgeData(edgeId, { hello: 'mona' }) // find the edge in the state by its id const edge = instance.findEdge(edgeId) edge.data = { ...edge.data, hello: 'world', } // you can also mutate properties like `selectable` or `animated` edge.selectable = !edge.selectable edge.animated = !edge.animated ``` ```vue [useEdge] ``` ```vue [v-model] ``` ::: ## [Predefined Edge-Types](/typedocs/interfaces/DefaultEdgeTypes) Vue Flow provides several built-in edge types that you can leverage immediately. The included node types are `default` (bezier), `step`, `smoothstep` and `straight`. ### Default Edge (Bezier) The default edge is a bezier curve that connects two nodes.
### Step Edge A step edge has a straight path with a step towards the target.
### Smoothstep Edge The same as the step edge though with a border radius on the step (rounded step).
### Straight Edge A simple straight path.
## User-Defined Edges On top of the default edge types mentioned earlier, you can create as many custom edge-types as you need. Edge-types are determined from your edges' definitions. ::: code-group ```vue [App.vue ] ``` ```vue [CustomEdge.vue ] ``` ```vue{25-26,32-33,40-42} [App.vue ] ``` ```vue [CustomEdge.vue ] ``` ::: Vue Flow will then attempt to resolve this edge-type to a component. Priority is given to a definition in the edgeTypes object of the state. Next, it tries to match the component to a globally registered one with the same name. Finally, it searches for a provided template slot to fill in the edge-type. If no methods produce a result in resolving the component, the default edge-type is used as a fallback. ### Template slots One of the easiest ways to define custom edges is, by passing them as template slots. Dynamic resolution to slot-names is done for your user-defined edge-types, meaning a edge with the type `custom` is expected to have a slot named `#edge-custom`. ```vue ``` ### Edge-types object Alternatively, edge-types can also be defined by passing an object as a prop to the VueFlow component (or as an option to the composable). ::: warning Take precaution to mark your components as raw (utilizing the marked function from the Vue library) to prevent their conversion into reactive objects. Otherwise, Vue will display a warning on the console. ::: ```vue ``` ## [Edge Props](/typedocs/interfaces/EdgeProps) Your custom edges are enclosed so that fundamental functions like selecting operate. But you may wish to expand on these features or implement your business logic inside edges, thus your edges receive the following properties: | Prop Name | Description | Type | Optional | |------------------|--------------------------------------------|----------------------------------------------|--------------------------------------------| | id | Unique edge id | string | | | sourceNode | The originating node | [GraphNode](/typedocs/interfaces/GraphNode) | | | targetNode | The destination node | [GraphNode](/typedocs/interfaces/GraphNode) | | | source | ID of the source node | string | | | target | ID of the target node | string | | | type | Edge Type | string | | | label | Edge label, can be a string or a VNode | string \| VNode \| Component \| Object | | | style | CSS properties | CSSProperties | | | selected | Is edge selected | boolean | | | sourcePosition | Source position | [Position](/typedocs/enumerations/Position) | | | targetPosition | Target position | [Position](/typedocs/enumerations/Position) | | | sourceHandleId | ID of the source handle | string | | | targetHandleId | ID of the target handle | string | | | animated | Is edge animated | boolean | | | updatable | Is edge updatable | boolean | | | markerStart | Start marker | string | | | markerEnd | End marker | string | | | curvature | The curvature of the edge | number | | | interactionWidth | Width of the interaction area for the edge | number | | | data | Additional data of edge | any object | | | events | Contextual and custom events of edge | [EdgeEventsOn](/typedocs/type-aliases/EdgeEventsOn) | | ## Edge Events Vue Flow provides two main ways of listening to edge events, either by using `useVueFlow` to bind listeners to the event handlers or by binding them to the `` component. ::: code-group ```vue [useVueFlow] ``` ```vue [component] ``` :::

Interact to see events in browser console

## Customizing Appearance ::: tip To override the styles of the default theme, visit the [Theming section](/guide/theming). :::