useVueFlow()
The useVueFlow composable returns the Vue Flow instance: a curated set of actions
(setNodes, addEdges, updateNodeData, deleteElements, …), computed getters
(getNodes, getEdges, getSelectedNodes, viewport), the viewport helpers
(fitView, zoomIn, setCenter, screenToFlowPosition, …), and the on* event
hooks (onConnect, onNodeDragStop, onInit, …).
It must run inside a flow provided by <VueFlow />,
<VueFlowProvider />, or
setupVueFlow() — otherwise it throws.
<script setup lang="ts">
import { useVueFlow } from '@xyflow/vue';
const { fitView, setNodes, onConnect } = useVueFlow();
onConnect((connection) => {
console.log('new connection', connection);
});
</script>Signature
Parameters:This function does not accept any parameters.
Returns:Notes
useVueFlowreturns the curated instance, not raw state. To read the reactive store directly (e.g.nodeLookup,transform), useuseVueFlowStore()— optionally withstoreToRefs().- Several things that are standalone hooks in React/Svelte Flow are methods on this
instance in Vue Flow — e.g.
updateNodeInternals,getViewport/setViewport, and the selection/viewport event hooks (onSelectionChange,onViewportChange).