@@ -649,6 +649,77 @@ User-created nodes don't have any default styles associated and thus need custom
649
649
}
650
650
```
651
651
652
+ ## Updating Node Data
653
+
654
+ Since nodes are reactive object, you can update their data at any point by simply mutating it.
655
+ This allows you to disable or enable handles, change the label, or even add new properties to the data object at any point in time.
656
+
657
+ There are multiple ways of achieving this, here are some examples:
658
+
659
+ ::: code-group
660
+
661
+ ``` vue [useNode]
662
+ <!-- CustomNode.vue -->
663
+ <script setup>
664
+ import { useNode } from '@vue-flow/core'
665
+
666
+ // `useNode` returns us the node object straight from the state
667
+ // since the node obj is reactive, we can mutate it to update our nodes' data
668
+ const { node } = useNode()
669
+
670
+ function onSomeEvent() {
671
+ node.data = {
672
+ ...node.data,
673
+ hello: 'world',
674
+ }
675
+ }
676
+ </script>
677
+ ```
678
+
679
+ ``` ts [useVueFlow]
680
+ import { useVueFlow } from ' @vue-flow/core'
681
+
682
+ const instance = useVueFlow ()
683
+
684
+ // find the node in the state by its id
685
+ const node = instance .findNode (nodeId )
686
+
687
+ node .data = {
688
+ ... node .data ,
689
+ hello: ' world' ,
690
+ }
691
+ ```
692
+
693
+ ``` vue [v-model]
694
+ <script setup>
695
+ import { ref } from 'vue'
696
+
697
+ const elements = ref([
698
+ {
699
+ id: '1',
700
+ label: 'Node 1',
701
+ position: { x: 50, y: 50 },
702
+ data: {
703
+ hello: 'world',
704
+ }
705
+ },
706
+ ])
707
+
708
+ function onSomeEvent() {
709
+ elements.value[0].data = {
710
+ ...elements.value[0].data,
711
+ hello: 'world',
712
+ }
713
+ }
714
+ </script>
715
+
716
+ <template>
717
+ <VueFlow v-model="elements" />
718
+ </template>
719
+ ```
720
+
721
+ :::
722
+
652
723
## Implementing Scrolling within Nodes
653
724
654
725
Sometimes, a node might contain a large amount of content, making it difficult for users to view everything without the aid of a scroll function.
0 commit comments