@@ -433,8 +433,13 @@ Edge-types are determined from your edges' definitions.
433
433
434
434
::: code-group
435
435
436
- ``` js [edges <LogosJavascript />]
436
+ ``` vue [App.vue <LogosJavascript />]
437
+ <script setup>
437
438
import { ref } from 'vue'
439
+ import { VueFlow } from '@vue-flow/core'
440
+
441
+ import CustomEdge from './CustomEdge.vue'
442
+ import SpecialEdge from './SpecialEdge.vue'
438
443
439
444
export const edges = ref([
440
445
{
@@ -445,22 +450,57 @@ export const edges = ref([
445
450
type: 'custom',
446
451
},
447
452
{
448
- id: ' e1-2 ' ,
453
+ id: 'e1-3 ',
449
454
source: '1',
450
- target: ' 2 ' ,
455
+ target: '3 ',
451
456
// this will create the edge-type `special`
452
457
type: 'special',
453
458
}
454
459
])
460
+
461
+ const nodes = ref([
462
+ {
463
+ id: '1',
464
+ label: 'Node 1',
465
+ position: { x: 50, y: 50 },
466
+ },
467
+ {
468
+ id: '2',
469
+ label: 'Node 2',
470
+ position: { x: 50, y: 250 },
471
+ },
472
+ {
473
+ id: '3',
474
+ label: 'Node 3',
475
+ position: { x: 250, y: 50 },
476
+ },
477
+ {
478
+ id: '4',
479
+ label: 'Node 4',
480
+ position: { x: 250, y: 250 },
481
+ },
482
+ ])
483
+ </script>
484
+
485
+ <template>
486
+ <VueFlow :nodes="nodes" :edges="edges">
487
+ <template #edge-custom="customEdgeProps">
488
+ <CustomEdge v-bind="customEdgeProps" />
489
+ </template>
490
+
491
+ <template #edge-special="specialEdgeProps">
492
+ <SpecialEdge v-bind="specialEdgeProps" />
493
+ </template>
494
+ </VueFlow>
495
+ </template>
455
496
```
456
497
457
498
``` vue [CustomEdge.vue <LogosJavascript />]
458
499
<script setup>
459
500
import { BezierEdge } from '@vue-flow/core';
460
501
502
+ // props were passed from the slot using `v-bind="customEdgeProps"`
461
503
const props = defineProps(['sourceX', 'sourceY', 'targetX', 'targetY', 'sourcePosition', 'targetPosition']);
462
-
463
- console.log(props.data.hello) // 'world'
464
504
</script>
465
505
466
506
<script lang="ts">
@@ -481,9 +521,14 @@ export default {
481
521
</template>
482
522
```
483
523
484
- ``` ts [edges <LogosTypescript />]
524
+ ``` vue{25-26,32-33,40-42} [App.vue <LogosTypescript />]
525
+ <script setup lang="ts">
485
526
import { ref } from 'vue'
486
527
import type { Edge } from '@vue-flow/core'
528
+ import { VueFlow } from '@vue-flow/core'
529
+
530
+ import CustomEdge from './CustomEdge.vue'
531
+ import SpecialEdge from './SpecialEdge.vue'
487
532
488
533
// You can pass 3 optional generic arguments to the Edge type, allowing you to define:
489
534
// 1. The data object type
@@ -496,33 +541,69 @@ interface CustomData {
496
541
497
542
type CustomEdgeTypes = 'custom' | 'special'
498
543
499
- type CustomEdge = Edge <CustomEdgeData , any , CustomEdgeTypes >
544
+ type CustomEdge = Edge<CustomData , any, CustomEdgeTypes>
500
545
501
546
export const edges = ref<CustomEdge[]>([
502
547
{
503
- id: ' e1-2' ,
504
- source: ' 1' ,
505
- target: ' 2' ,
506
- // this will create the edge-type `custom`
507
- type: ' custom' ,
548
+ id: 'e1-2',
549
+ source: '1',
550
+ target: '2',
551
+ // this will create the edge-type `custom`
552
+ type: 'custom',
508
553
},
509
554
{
510
- id: ' e1-2 ' ,
511
- source: ' 1' ,
512
- target: ' 2 ' ,
513
- // this will create the edge-type `special`
514
- type: ' special' ,
555
+ id: 'e1-3 ',
556
+ source: '1',
557
+ target: '3 ',
558
+ // this will create the edge-type `special`
559
+ type: 'special',
515
560
},
516
561
517
- // this will throw a type error, as the type is not defined in the CustomEdgeTypes
518
- // regardless it would be rendered as a default edge type
519
562
{
520
- id: ' e1-2' ,
521
- source: ' 1' ,
522
- target: ' 2' ,
523
- type: ' not-defined' , // should be 'custom' | 'special'
563
+ id: 'e1-4',
564
+ source: '1',
565
+ target: '4',
566
+ // this will throw a type error, as the type is not defined in the CustomEdgeTypes
567
+ // regardless it would be rendered as a default edge type
568
+ type: 'not-defined',
524
569
}
525
570
])
571
+
572
+ const nodes = ref([
573
+ {
574
+ id: '1',
575
+ label: 'Node 1',
576
+ position: { x: 50, y: 50 },
577
+ },
578
+ {
579
+ id: '2',
580
+ label: 'Node 2',
581
+ position: { x: 50, y: 250 },
582
+ },
583
+ {
584
+ id: '3',
585
+ label: 'Node 3',
586
+ position: { x: 250, y: 50 },
587
+ },
588
+ {
589
+ id: '4',
590
+ label: 'Node 4',
591
+ position: { x: 250, y: 250 },
592
+ },
593
+ ])
594
+ </script>
595
+
596
+ <template>
597
+ <VueFlow :nodes="nodes" :edges="edges">
598
+ <template #edge-custom="customEdgeProps">
599
+ <CustomEdge v-bind="customEdgeProps" />
600
+ </template>
601
+
602
+ <template #edge-special="specialEdgeProps">
603
+ <SpecialEdge v-bind="specialEdgeProps" />
604
+ </template>
605
+ </VueFlow>
606
+ </template>
526
607
```
527
608
528
609
``` vue [CustomEdge.vue <LogosTypescript />]
@@ -532,6 +613,7 @@ import { BezierEdge } from '@vue-flow/core';
532
613
533
614
import { CustomData } from './edges'
534
615
616
+ // props were passed from the slot using `v-bind="customEdgeProps"`
535
617
const props = defineProps<EdgeProps<CustomData>>();
536
618
537
619
console.log(props.data.hello) // 'world'
@@ -676,8 +758,7 @@ But you may wish to expand on these features or implement your business logic in
676
758
## Edge Events
677
759
678
760
Vue Flow provides two main ways of listening to edge events,
679
- either by using ` useVueFlow ` to bind listeners to the event handlers
680
- or by using binding listeners to the ` <VueFlow> ` component.
761
+ either by using ` useVueFlow ` to bind listeners to the event handlers or by binding them to the ` <VueFlow> ` component.
681
762
682
763
::: code-group
683
764
0 commit comments