@@ -678,3 +678,84 @@ const elements = ref([
678
678
::: tip
679
679
To override the styles of the default theme, visit the [ Theming section] ( /guide/theming ) .
680
680
:::
681
+
682
+ ## Updating Edge Data
683
+
684
+ Since edges are reactive object, you can update their data at any point by simply mutating it.
685
+ This allows you to change the label, or even add new properties to the data object at any point in time.
686
+
687
+ There are multiple ways of achieving this, here are some examples:
688
+
689
+ ::: code-group
690
+
691
+ ``` vue [useEdge]
692
+ <!-- CustomEdge.vue -->
693
+ <script setup>
694
+ import { useEdge } from '@vue-flow/core'
695
+
696
+ // `useEdge` returns us the edge object straight from the state
697
+ // since the node obj is reactive, we can mutate it to update our edges' data
698
+ const { edge } = useEdge()
699
+
700
+ function onSomeEvent() {
701
+ edge.data = {
702
+ ...edge.data,
703
+ hello: 'world',
704
+ }
705
+ }
706
+ </script>
707
+ ```
708
+
709
+ ``` ts [useVueFlow]
710
+ import { useVueFlow } from ' @vue-flow/core'
711
+
712
+ const instance = useVueFlow ()
713
+
714
+ // find the node in the state by its id
715
+ const edge = instance .findEdge (edgeId )
716
+
717
+ edge .data = {
718
+ ... edge .data ,
719
+ hello: ' world' ,
720
+ }
721
+ ```
722
+
723
+ ``` vue [v-model]
724
+ <script setup>
725
+ import { ref } from 'vue'
726
+
727
+ const elements = ref([
728
+ {
729
+ id: '1',
730
+ label: 'Node 1',
731
+ position: { x: 50, y: 50 },
732
+ data: {
733
+ hello: 'world',
734
+ }
735
+ },
736
+ {
737
+ id: '2',
738
+ label: 'Node 2',
739
+ position: { x: 50, y: 250 },
740
+ },
741
+ {
742
+ id: 'e1-2',
743
+ source: '1',
744
+ target: '2',
745
+ },
746
+ ])
747
+
748
+ function onSomeEvent() {
749
+ elements.value[2].data = {
750
+ ...elements.value[0].data,
751
+ hello: 'world',
752
+ }
753
+ }
754
+ </script>
755
+
756
+ <template>
757
+ <VueFlow v-model="elements" />
758
+ </template>
759
+ ```
760
+
761
+ :::
0 commit comments