Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(guide): add docs section about v-modelling nodes and edges #1715

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/src/guide/controlled-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,38 @@ const onNodesChange = async (changes) => {
<VueFlow :nodes="nodes" :edges="edges" :apply-default="false" @nodes-change="onNodesChange" />
</template>
```

## V-Model Nodes and Edges

In some cases you want to *sync* the state of internal nodes/edges with your own state,
for those cases you can use the `v-model` directive to bind the internal state with your own state.

```vue
<template>
<VueFlow v-model:edges="edges" v-model:nodes="nodes" />
</template>
```

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.

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.

```vue
<script setup>
import { ref } from 'vue'
import { useVueFlow } from '@vue-flow/core'

const nodes = ref([
{
id: '1',
position: { x: 0, y: 0 },
data: { label: 'Node 1' },
},
])

const { updateNode } = useVueFlow()

// using updateNode will only update the internal state, not the nodes state unless you use v-model
updateNode('1', { type: 'new-type' })
</script>
```
Loading