|
1 | 1 | <script setup>
|
2 |
| -import { Background } from '@vue-flow/background' |
3 |
| -import { Panel, VueFlow, useVueFlow } from '@vue-flow/core' |
4 | 2 | import { ref, watch } from 'vue'
|
| 3 | +import { Background } from '@vue-flow/background' |
| 4 | +import { Panel, VueFlow } from '@vue-flow/core' |
5 | 5 |
|
6 |
| -const isHidden = ref(false) |
| 6 | +const nodes = ref([ |
| 7 | + { id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } }, |
| 8 | + { id: '2', label: 'Node 2', position: { x: 100, y: 100 } }, |
| 9 | + { id: '3', label: 'Node 3', position: { x: 400, y: 100 } }, |
| 10 | + { id: '4', label: 'Node 4', position: { x: 400, y: 200 } }, |
| 11 | +]) |
7 | 12 |
|
8 |
| -const { nodes, edges } = useVueFlow({ |
9 |
| - nodes: [ |
10 |
| - { id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } }, |
11 |
| - { id: '2', label: 'Node 2', position: { x: 100, y: 100 } }, |
12 |
| - { id: '3', label: 'Node 3', position: { x: 400, y: 100 } }, |
13 |
| - { id: '4', label: 'Node 4', position: { x: 400, y: 200 } }, |
14 |
| - ], |
15 |
| - edges: [ |
16 |
| - { id: 'e1-2', source: '1', target: '2' }, |
17 |
| - { id: 'e1-3', source: '1', target: '3' }, |
18 |
| - { id: 'e3-4', source: '3', target: '4' }, |
19 |
| - ], |
20 |
| -}) |
| 13 | +const edges = ref([ |
| 14 | + { id: 'e1-2', source: '1', target: '2' }, |
| 15 | + { id: 'e1-3', source: '1', target: '3' }, |
| 16 | + { id: 'e3-4', source: '3', target: '4' }, |
| 17 | +]) |
| 18 | +
|
| 19 | +const isHidden = ref(false) |
21 | 20 |
|
22 | 21 | watch(isHidden, () => {
|
23 |
| - nodes.value.forEach((n) => (n.hidden = isHidden.value)) |
24 |
| - edges.value.forEach((e) => (e.hidden = isHidden.value)) |
| 22 | + nodes.value = nodes.value.map((node) => ({ ...node, hidden: isHidden.value })) |
| 23 | + edges.value = edges.value.map((edge) => ({ ...edge, hidden: isHidden.value })) |
25 | 24 | })
|
26 | 25 | </script>
|
27 | 26 |
|
28 | 27 | <template>
|
29 |
| - <VueFlow fit-view-on-init> |
| 28 | + <VueFlow :nodes="nodes" :edges="edges" fit-view-on-init> |
30 | 29 | <Background />
|
31 | 30 |
|
32 | 31 | <Panel position="top-right">
|
|
0 commit comments