Skip to content

Commit 2231ee4

Browse files
committed
docs(guide): add docs section about v-modelling nodes and edges
Signed-off-by: braks <[email protected]>
1 parent fe239b5 commit 2231ee4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

docs/src/guide/controlled-flow.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,38 @@ const onNodesChange = async (changes) => {
211211
<VueFlow :nodes="nodes" :edges="edges" :apply-default="false" @nodes-change="onNodesChange" />
212212
</template>
213213
```
214+
215+
## V-Model Nodes and Edges
216+
217+
In some cases you want to *sync* the state of internal nodes/edges with your own state,
218+
for those cases you can use the `v-model` directive to bind the internal state with your own state.
219+
220+
```vue
221+
<template>
222+
<VueFlow v-model:edges="edges" v-model:nodes="nodes" />
223+
</template>
224+
```
225+
226+
Doing this will sync the internal state with your own state, which is useful for situations where you update internal nodes and edges but also want those changes to be reflected in your own state.
227+
228+
For example, if you update the type of nodes using `updateNode` and want to see the same change reflected in your own nodes state and not just in the internal state.
229+
230+
```vue
231+
<script setup>
232+
import { ref } from 'vue'
233+
import { useVueFlow } from '@vue-flow/core'
234+
235+
const nodes = ref([
236+
{
237+
id: '1',
238+
position: { x: 0, y: 0 },
239+
data: { label: 'Node 1' },
240+
},
241+
])
242+
243+
const { updateNode } = useVueFlow()
244+
245+
// using updateNode will only update the internal state, not the nodes state unless you use v-model
246+
updateNode('1', { type: 'new-type' })
247+
</script>
248+
```

0 commit comments

Comments
 (0)