The @freeplaceholder/vue package provides <FpPlaceholder> and <FpAvatar> components, plus composables for Vue 3.
Installation
bash
npm install https://github.com/freeplaceholder/vuePlaceholder Component
vue
<script setup>
import { FpPlaceholder } from "@freeplaceholder/vue";
</script>
<template>
<FpPlaceholder
:width="800"
:height="400"
text="Hero Banner"
format="webp"
bg="3b82f6"
text-color="ffffff"
font-weight="bold"
rounded="lg"
/>
</template>Placeholder Props
| Prop | Type | Description | |
|---|---|---|---|
| width | number | Image width in px (required) | |
| height | number | Image height in px (required) | |
| format | ImageFormat | Output format: svg, png, jpg, webp | |
| bg | string | Background hex color | |
| gradient | GradientDirection | to-t, to-tr, to-r, to-br, to-b, to-bl, to-l, to-tl, radial | |
| from | string | Gradient start color — hex without # | |
| via | string | Gradient middle color — hex without # | |
| to | string | Gradient end color — hex without # | |
| textColor / text-color | string | Text hex color | |
| text | string | Custom text overlay | |
| textSize / text-size | number | Font size in px | |
| textAlign / text-align | TextAlign | left, center, right | |
| textTransform / text-transform | TextTransform | uppercase, lowercase, capitalize, none | |
| textDecoration / text-decoration | TextDecoration | underline, overline, line-through, none | |
| letterSpacing / letter-spacing | `LetterSpacing \ | string` | tighter, tight, wide, wider, widest, or px |
| fontWeight / font-weight | FontWeight | Font weight | |
| opacity | number | 0–100 | |
| grayscale | boolean | Grayscale filter | |
| blur | number | Gaussian blur 0–100 px | |
| brightness | number | 0–200 | |
| contrast | number | 0–200 | |
| hueRotate / hue-rotate | number | 0–360 degrees | |
| invert | boolean | Invert colors | |
| saturate | number | 0–200 | |
| sepia | boolean | Sepia tone | |
| border | number | Border width in px | |
| borderColor / border-color | string | Border hex color | |
| borderStyle / border-style | BorderStyle | Border style | |
| rounded | `Rounded \ | number` | Border radius |
| lazy | boolean | Enable lazy loading (default: true) |
Avatar Component
vue
<script setup>
import { FpAvatar } from "@freeplaceholder/vue";
</script>
<template>
<FpAvatar
name="John Doe"
:size="64"
format="png"
font-weight="bold"
:border="2"
border-color="ffffff"
/>
</template>Avatar Props
| Prop | Type | Description | |
|---|---|---|---|
| name | string | Name to derive initials from (required) | |
| size | number | Square dimensions in px (default: 128) | |
| format | ImageFormat | Output format | |
| bg | string | Background hex color | |
| gradient | GradientDirection | to-t, to-tr, to-r, to-br, to-b, to-bl, to-l, to-tl, radial | |
| from | string | Gradient start color — hex without # | |
| via | string | Gradient middle color — hex without # | |
| to | string | Gradient end color — hex without # | |
| textColor / text-color | string | Text hex color | |
| textDecoration / text-decoration | TextDecoration | underline, overline, line-through, none | |
| letterSpacing / letter-spacing | `LetterSpacing \ | string` | Letter spacing |
| fontWeight / font-weight | FontWeight | Font weight | |
| opacity | number | 0–100 | |
| grayscale | boolean | Grayscale filter | |
| blur | number | Gaussian blur 0–100 px | |
| brightness | number | 0–200 | |
| contrast | number | 0–200 | |
| hueRotate / hue-rotate | number | 0–360 degrees | |
| invert | boolean | Invert colors | |
| saturate | number | 0–200 | |
| sepia | boolean | Sepia tone | |
| border | number | Border width in px | |
| borderColor / border-color | string | Border hex color | |
| borderStyle / border-style | BorderStyle | Border style | |
| rounded | `Rounded \ | number` | Border radius |
| lazy | boolean | Enable lazy loading (default: true) |
Composables
For more control, use the composables that return reactive URL strings:
vue
<script setup>
import { usePlaceholderUrl, useAvatarUrl } from "@freeplaceholder/vue";
import { ref, computed } from "vue";
const width = ref(600);
const src = usePlaceholderUrl(
computed(() => ({ width: width.value, height: 400, bg: "3b82f6" }))
);
const avatar = useAvatarUrl({ name: "Alice", size: 96, format: "png" });
</script>
<template>
<img :src="src" alt="Placeholder" />
<img :src="avatar" alt="Alice" />
</template>TypeScript
ts
import type {
PlaceholderComponentProps,
AvatarComponentProps,
FontWeight,
} from "@freeplaceholder/vue";Overriding Base URL
ts
import { configure } from "@freeplaceholder/vue";
configure({ baseUrl: "https://my-custom-instance.com" });