useQrCode
QrCode
stable
Headless QR-code composable. Encodes a string payload using qrcode-generator (Reed-Solomon + matrix masking) and returns a reactive SVG string, the raw module matrix, and the matrix size. The encoder is LRU-cached at module level to avoid rebuilding identical matrices on re-renders. Fully SSR-safe — no DOM API is touched.
API
Signature
Full TypeScript signature sourced from the composable file.
Consumed interfaces
IUseQrCodeOptions
IQrCodeLogo
API
Parameters
Input parameters accepted by this composable.
- valuerequiredMaybeRefOrGetter<string>
- The payload to encode: URL, text, vCard, etc. Accepts a plain string, a ref, or a getter function. Reactive — the SVG rebuilds whenever value changes.
- optionsMaybeRefOrGetter<IUseQrCodeOptions>{}
- Encoding and rendering options: errorCorrectionLevel ("L" | "M" | "Q" | "H"), foreground, background, margin (module units), cornerRadius (per <rect>), and logo ({ src, size, padding, background }).
API
Return values
Properties and methods exposed by the composable return object.
- svg
- Complete SVG string with a viewBox scaled to the module grid. Safe for v-html or <img src="data:image/svg+xml,…">. Rebuilds when value or options change.
- modules
- N×N boolean grid where true = dark module. Use to render a custom canvas or WebGL QR code.
- size
- The side length of the module matrix (modules.value.length). Grows with payload complexity and ECC level.
Usage
Examples
Ready-to-paste usage snippets.
Basic reactive QR code
Via OrigamQrCode component
Custom canvas rendering using modules