1
+ <script setup >
2
+ import LogosJavascript from ' ~icons/logos/javascript' ;
3
+ import LogosTypescript from ' ~icons/logos/typescript-icon' ;
4
+ </script >
5
+
1
6
# Kickstart Your Journey with Vue Flow!
2
7
3
8
This guide covers the basics of setting up and using Vue Flow. You'll learn how to install Vue Flow, configure it, and
@@ -50,33 +55,164 @@ Refer to the [Theming](/guide/theming) section for additional information.
50
55
51
56
Here's a simple Vue Flow example to get you started:
52
57
53
- ``` vue
58
+ ::: code-group
59
+
60
+ ``` vue [<LogosJavascript />]
54
61
<script setup>
55
62
import { VueFlow } from '@vue-flow/core'
56
63
64
+ import SpecialNode from './components/SpecialNode.vue'
65
+ import SpecialEdge from './components/SpecialEdge.vue'
66
+
57
67
const elements = ref([
58
- // Nodes
59
- // An input node, specified by using `type: 'input'`
68
+ // nodes
69
+
70
+ // an input node, specified by using `type: 'input'`
60
71
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
61
72
62
- // Default nodes , you can omit `type: 'default'`
73
+ // default node , you can omit `type: 'default'` as it's the fallback type
63
74
{ id: '2', label: 'Node 2', position: { x: 100, y: 100 }, },
64
- { id: '3', label: 'Node 3', position: { x: 400, y: 100 } },
65
75
66
76
// An output node, specified by using `type: 'output'`
67
- { id: '4', type: 'output', label: 'Node 4', position: { x: 400, y: 200 } },
77
+ { id: '3', type: 'output', label: 'Node 3', position: { x: 400, y: 200 } },
78
+
79
+ // A custom node, specified by using a custom type name
80
+ // we choose `type: 'special'` for this example
81
+ {
82
+ id: '4',
83
+ type: 'special',
84
+ label: 'Node 4',
85
+ position: { x: 400, y: 200 },
86
+
87
+ // pass custom data to the node
88
+ data: {
89
+ // you can pass any data you want to the node
90
+ hello: 'world',
91
+ },
92
+ },
93
+
94
+ // edges
95
+
96
+ // simple default bezier edge
97
+ // consists of an id, source-id and target-id
98
+ { id: 'e1-3', source: '1', target: '3' },
99
+
100
+ // an animated edge, specified by using `animated: true`
101
+ { id: 'e1-2', source: '1', target: '2', animated: true },
68
102
69
- // Edges
70
- // Most basic edge, only consists of an id, source-id and target-id
103
+ // a custom edge, specified by using a custom type name
104
+ // we choose `type: 'special'` for this example
105
+ {
106
+ id: 'e1-4',
107
+ type: 'special',
108
+ source: '1',
109
+ target: '4',
110
+
111
+ // pass custom data to the edge
112
+ data: {
113
+ // You can pass any data you want to the edge
114
+ hello: 'world',
115
+ }
116
+ },
117
+ ])
118
+ </script>
119
+
120
+ <template>
121
+ <VueFlow v-model="elements">
122
+ <!-- bind your custom node type to a component by using slots, slot names are always `node-<type>` -->
123
+ <template #node-special="specialNodeProps">
124
+ <SpecialNode v-bind="specialNodeProps" />
125
+ </template>
126
+
127
+ <!-- bind your custom edge type to a component by using slots, slot names are always `edge-<type>` -->
128
+ <template #edge-special="specialEdgeProps">
129
+ <SpecialEdge v-bind="specialEdgeProps" />
130
+ </template>
131
+ </VueFlow>
132
+ </template>
133
+
134
+ <style>
135
+ /* import the necessary styles for Vue Flow to work */
136
+ @import '@vue-flow/core/dist/style.css';
137
+
138
+ /* import the default theme, this is optional but generally recommended */
139
+ @import '@vue-flow/core/dist/theme-default.css';
140
+ </style>
141
+ ```
142
+
143
+ ``` vue [<LogosTypescript />]
144
+ <script setup lang="ts">
145
+ import type { Elements } from '@vue-flow/core'
146
+ import { VueFlow } from '@vue-flow/core'
147
+
148
+ import SpecialNode from './components/SpecialNode.vue'
149
+ import SpecialEdge from './components/SpecialEdge.vue'
150
+
151
+ const elements = ref<Elements>([
152
+ // nodes
153
+
154
+ // an input node, specified by using `type: 'input'`
155
+ { id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
156
+
157
+ // default node, you can omit `type: 'default'` as it's the fallback type
158
+ { id: '2', label: 'Node 2', position: { x: 100, y: 100 }, },
159
+
160
+ // An output node, specified by using `type: 'output'`
161
+ { id: '3', type: 'output', label: 'Node 3', position: { x: 400, y: 200 } },
162
+
163
+ // A custom node, specified by using a custom type name
164
+ // we choose `type: 'special'` for this example
165
+ {
166
+ id: '4',
167
+ type: 'special',
168
+ label: 'Node 4',
169
+ position: { x: 400, y: 200 },
170
+
171
+ // pass custom data to the node
172
+ data: {
173
+ // you can pass any data you want to the node
174
+ hello: 'world',
175
+ },
176
+ },
177
+
178
+ // edges
179
+
180
+ // simple default bezier edge
181
+ // consists of an id, source-id and target-id
71
182
{ id: 'e1-3', source: '1', target: '3' },
72
183
73
- // An animated edge
184
+ // an animated edge, specified by using `animated: true`
74
185
{ id: 'e1-2', source: '1', target: '2', animated: true },
186
+
187
+ // a custom edge, specified by using a custom type name
188
+ // we choose `type: 'special'` for this example
189
+ {
190
+ id: 'e1-4',
191
+ type: 'special',
192
+ source: '1',
193
+ target: '4',
194
+
195
+ // pass custom data to the edge
196
+ data: {
197
+ // You can pass any data you want to the edge
198
+ hello: 'world',
199
+ }
200
+ },
75
201
])
76
202
</script>
77
203
78
204
<template>
79
- <VueFlow v-model="elements"/>
205
+ <VueFlow v-model="elements">
206
+ <!-- bind your custom node type to a component by using slots, slot names are always `node-<type>` -->
207
+ <template #node-special="specialNodeProps">
208
+ <SpecialNode v-bind="specialNodeProps" />
209
+ </template>
210
+
211
+ <!-- bind your custom edge type to a component by using slots, slot names are always `edge-<type>` -->
212
+ <template #edge-special="specialEdgeProps">
213
+ <SpecialEdge v-bind="specialEdgeProps" />
214
+ </template>
215
+ </VueFlow>
80
216
</template>
81
217
82
218
<style>
@@ -88,6 +224,8 @@ const elements = ref([
88
224
</style>
89
225
```
90
226
227
+ :::
228
+
91
229
## TypeScript
92
230
93
231
As Vue Flow is entirely written in TypeScript, we highly recommend utilizing TypeScript for improved developer
0 commit comments