Skip to content

Commit a7a9fd5

Browse files
committed
docs(guide): add info on listening to events
Signed-off-by: braks <[email protected]>
1 parent f4bffeb commit a7a9fd5

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

docs/src/.vitepress/config.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ export default defineConfigWithTheme<DefaultTheme.Config>({
159159
items: [
160160
{ text: 'Configuration', link: '/guide/vue-flow/config' },
161161
{ text: 'State', link: '/guide/vue-flow/state' },
162+
{
163+
text: 'Events',
164+
link: '/guide/vue-flow/events',
165+
},
162166
{
163167
text: 'Actions',
164168
link: '/typedocs/interfaces/Actions.html',
@@ -167,10 +171,6 @@ export default defineConfigWithTheme<DefaultTheme.Config>({
167171
text: 'Getters',
168172
link: '/typedocs/interfaces/Getters.html',
169173
},
170-
{
171-
text: 'Events',
172-
link: '/typedocs/interfaces/FlowEvents.html',
173-
},
174174
{ text: 'Slots', link: '/guide/vue-flow/slots' },
175175
],
176176
},

docs/src/guide/vue-flow/events.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Events
3+
---
4+
5+
# Events
6+
7+
VueFlow provides a set of events that you can listen to in order to react to changes in the flow.
8+
9+
A full list of events can be found in the [API Reference](/typedocs/interfaces/FlowEvents.html).
10+
11+
## Listening to Events
12+
13+
### VueFlow Component
14+
15+
You can listen to events on the VueFlow component by using the `@` directive:
16+
17+
```vue
18+
<script setup>
19+
import { ref } from 'vue';
20+
import { VueFlow } from '@vue-flow/core';
21+
22+
const nodes = ref([/* ... */]);
23+
const edges = ref([/* ... */]);
24+
25+
// Node click event handler
26+
function onNodeClick({ event, node }) {
27+
console.log('Node clicked:', node, event);
28+
}
29+
30+
// Edge click event handler
31+
function onEdgeClick({ event, edge }) {
32+
console.log('Edge clicked:', edge, event);
33+
}
34+
</script>
35+
36+
<template>
37+
<VueFlow :nodes="nodges" :edges="edges" @node-click="onNodeClick" @edge-click="onEdgeClick"></VueFlow>
38+
</template>
39+
```
40+
41+
### Flow Instance / `useVueFlow`
42+
43+
You can also listen to events on the Flow instance by using the event hooks.
44+
45+
All events are available from `useVueFlow` as `on<EventName>`. For example, the `node-click` event is available as `onNodeClick`.
46+
47+
```vue
48+
<script setup>
49+
import { ref } from 'vue';
50+
import { VueFlow, useVueFlow } from '@vue-flow/core';
51+
52+
const nodes = ref([/* ... */]);
53+
const edges = ref([/* ... */]);
54+
55+
// All events are available from `useVueFlow` as `on<EventName>`
56+
const { onNodeClick, onEdgeClick } = useVueFlow();
57+
58+
// Node click event handler
59+
onNodeClick(({ event, node }) => {
60+
console.log('Node clicked:', node, event);
61+
});
62+
63+
// Edge click event handler
64+
onEdgeClick(({ event, edge }) => {
65+
console.log('Edge clicked:', edge, event);
66+
});
67+
</script>
68+
69+
<template>
70+
<VueFlow :nodes="nodges" :edges="edges" @node-click="onNodeClick" @edge-click="onEdgeClick"></VueFlow>
71+
</template>
72+
```

0 commit comments

Comments
 (0)