<Background />
The <Background /> component makes it convenient to render different types of
backgrounds common in node-based UIs. It comes with three variants: lines, dots
and cross.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Background, VueFlow } from '@xyflow/vue';
const nodes = shallowRef([]);
const edges = shallowRef([]);
</script>
<template>
<VueFlow v-model:nodes="nodes" v-model:edges="edges">
<Background color="#ccc" variant="dots" />
</VueFlow>
</template>Props
The type for props of <Background /> component is exported as BackgroundProps.
| Name | Type | Default |
|---|---|---|
id | string
This is necessary when you have multiple flows with backgrounds visible at the same time. If no id is explicitly assigned, an auto-generated one is used. | `pattern-${vueFlowId}${id ? `-${id}` : ''}` |
variant | BackgroundVariantThe background pattern variant BackgroundVariant | 'dots' |
gap | number | number[]The background pattern gap Can be either a number or [xGap: number, yGap: number], defining the gap on the X and Y axis respectively | 20 |
size | numberThe radius of each dot or the size of each rectangle if the Defaults to 1 or 6 respectively, and is ignored by the | |
lineWidth | numberThe stroke thickness used when drawing the pattern. | 1 |
color | stringThe background pattern color This only changes the color of the pattern, not the background color itself - use BackgroundProps.bgColor for that. | |
bgColor | stringThe background color | |
patternClassName | stringClass applied to the pattern | |
x | numberBackground x-coordinate (offset x) | 0 |
y | numberBackground y-coordinate (offset y) | 0 |
offset | number | [number, number]Background pattern offset | 0 |
Examples
Multiple backgrounds
It is possible to render multiple <Background /> components by giving each one a
distinct id. Combining variants — for example a fine dots grid over a wider
lines grid — makes for a nice layered effect.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Background, VueFlow } from '@xyflow/vue';
const nodes = shallowRef([]);
const edges = shallowRef([]);
</script>
<template>
<VueFlow v-model:nodes="nodes" v-model:edges="edges">
<Background id="1" :gap="10" color="#f1f1f1" variant="lines" />
<Background id="2" :gap="100" color="#ccc" variant="lines" />
</VueFlow>
</template>