Updatable Edge
Existing edges can be updated, meaning their source / target position can be changed interactively.
Update an edge by simply dragging it from one node to another at the edge-anchor (handles).
You can enable updating edges either globally by passing the edgesUpdatable
prop or you can enable it for specific edges by using the updatable
attribute.
App.vue
main.css
xxxxxxxxxx
58
<script setup>
import { Background } from '@vue-flow/background'
import { VueFlow, useVueFlow } from '@vue-flow/core'
import { ref } from 'vue'
const elements = ref([
{
id: '1',
type: 'input',
label: 'Node <strong>A</strong>',
position: { x: 250, y: 0 },
},
{
id: '2',
label: 'Node <strong>B</strong>',
position: { x: 100, y: 100 },
},
{
id: '3',
label: 'Node <strong>C</strong>',
position: { x: 400, y: 100 },
style: { background: '#D6D5E6', color: '#333', border: '1px solid #222138', width: 180 },
},
{ id: 'e1-2', source: '1', target: '2', label: 'Updateable edge', updatable: true },
])
const { updateEdge, addEdges } = useVueFlow()
function onEdgeUpdateStart(edge) {
return console.log('start update', edge)
}
function onEdgeUpdateEnd(edge) {
return console.log('end update', edge)
}
function onEdgeUpdate({ edge, connection }) {
return updateEdge(edge, connection)
}
function onConnect(params) {
return addEdges([params])
}
</script>
<template>
<VueFlow
v-model="elements"
fit-view-on-init
@edge-update="onEdgeUpdate"
@connect="onConnect"
@edge-update-start="onEdgeUpdateStart"
@edge-update-end="onEdgeUpdateEnd"
>
<Background />
</VueFlow>
</template>