@@ -14,12 +14,13 @@ const elements = ref<Elements>([
1414 { id: ' e1-2' , source: ' 1' , target: ' 2' , animated: true },
1515 { id: ' e1-3' , source: ' 1' , target: ' 3' },
1616])
17- const { onNodeDragStop, onEdgeClick, onConnect, addEdges, setTransform, toObject } = useVueFlow ({
18- minZoom: 0.2 ,
19- maxZoom: 4 ,
20- connectOnClick: true ,
21- fitViewOnInit: false ,
22- })
17+ const { onNodeDragStop, onEdgeClick, onConnect, addEdges, setTransform, toObject, fitView, onPaneReady, setNodes, setEdges } =
18+ useVueFlow ({
19+ minZoom: 0.2 ,
20+ maxZoom: 4 ,
21+ connectOnClick: true ,
22+ fitViewOnInit: false ,
23+ })
2324
2425onNodeDragStop ((e ) => console .log (' drag stop' , e .event ))
2526onEdgeClick (console .log )
@@ -35,13 +36,29 @@ const updatePos = () =>
3536 }
3637 })
3738
39+ onPaneReady ((instance ) => {
40+ setNodes ([
41+ { id: ' 1' , type: ' input' , label: ' Node 1' , position: { x: 250 , y: 5 }, class: ' light' },
42+ { id: ' 2' , label: ' Node 2' , position: { x: 100 , y: 100 }, class: ' light' },
43+ { id: ' 3' , label: ' Node 3' , position: { x: 400 , y: 100 }, class: ' light' },
44+ { id: ' 4' , label: ' Node 4' , position: { x: 400 , y: 200 }, class: ' light' },
45+ ])
46+
47+ setEdges ([
48+ { id: ' e1-2' , source: ' 1' , target: ' 2' , animated: true },
49+ { id: ' e1-3' , source: ' 1' , target: ' 3' },
50+ ])
51+
52+ instance .fitView ()
53+ })
54+
3855const logToObject = () => console .log (toObject ())
3956const resetTransform = () => setTransform ({ x: 0 , y: 0 , zoom: 1 })
4057const toggleclass = () => elements .value .forEach ((el ) => (el .class = el .class === ' light' ? ' dark' : ' light' ))
4158 </script >
4259
4360<template >
44- <VueFlow v-model =" elements" fit-view-on-init connection-mode =" strict" class =" vue-flow-basic-example" >
61+ <VueFlow v-model =" elements" connection-mode =" strict" class =" vue-flow-basic-example" >
4562 <Background />
4663 <MiniMap />
4764 <Controls />
0 commit comments