Qrcode
A QR code component (SVG form on web): the text goes through the self-built pure JS encoder in @lh-ui/share/core/qrcode to generate the module matrix (encodeQrcode), then qrcodeToSvgPath converts it into a dark-module path string rendered into <svg>. The encoder is self-built pure JS with zero third-party dependencies and full v1-40 support (byte mode, UTF-8 Chinese, four error-correction levels, automatic optimal mask selection). Supports error-correction level, version and quiet-zone passthrough, and color / size customization; an empty value and text exceeding the capacity degrade to an empty state (no svg rendered, logged with console.warn), never letting an encoding error bubble up to the rendering layer.
Boundary with Watermark: Watermark watermarks a page (a QR watermark is one of its sub-capabilities); Qrcode is a standalone display-only QR code component — no events, no slots, it only consumes props.
Basic Usage
value is the text to encode (UTF-8, supports Chinese); size controls the rendered pixel size (120 by default; the viewBox scales proportionally with the module count + quiet zone, so any size stays distortion-free):
<script setup lang="ts">
import { ref } from 'vue'
import { LhQrcode } from '@lh-ui/vue3'
const text = ref('https://www.lhgb.top/lhui/plus/')
</script>
<template>
<LhQrcode :value="text" />
<LhQrcode :value="text" :size="160" />
</template>Error-correction levels
level has four grades (L 7% / M 15% / Q 25% / H 30% fault tolerance); the higher the level, the denser the matrix for the same text. M is recommended for scanning scenarios (the default), and H for posters / packaging and other easily-soiled scenarios:
<LhQrcode :value="text" level="H" />version (1-40, default 0 = automatically pick the smallest version that fits) and margin (quiet-zone module count, 4 by default, the floor for scanning recognition) can be passed straight through to the encoder; for wrapped layouts, keeping it at 4 or above is recommended.
Custom colors and sizes
color overrides the module foreground color (falls back to the --lh-text-primary token / a dark color by default); bgColor draws a background rect (transparent when not passed, going through the stylesheet --lh-bg-color token):
<LhQrcode :value="text" color="#2B4C7C" :size="140" />
<LhQrcode :value="text" color="#D9393B" bg-color="#FFF7E8" :size="140" />API
Qrcode Props
| Prop | Description | Type | Default |
|---|---|---|---|
| value | Text to encode (UTF-8, supports Chinese; an empty value renders the empty state) | string | '' |
| level | Error-correction level (L 7% / M 15% / Q 25% / H 30% fault tolerance) | 'L' | 'M' | 'Q' | 'H' | 'M' |
| version | Version 1-40; 0 = automatically pick the smallest version that fits | number | 0 |
| margin | Quiet-zone module count (4 by default, the spec minimum) | number | 4 |
| color | Module foreground color (falls back to the lh-qrcode token / a dark color by default when not passed) | string | — |
| bgColor | Background color (no background rect drawn when not passed, going through the stylesheet token) | string | — |
| size | Rendered pixel size | number | 120 |
| label | Accessible name | string | — |
| sx | sx quick-layout props | LhSxProps | — |
Accessibility
- The root node is
role="img"; its accessible name defaults to "QR code" and can be overridden withlabel - The empty state (empty
value/ capacity-exceeded degradation) renders no svg and leaves no leftover nodes in the DOM - On encoding failure it is logged with
console.warnand degraded to an empty state, never throwing
The encoder is self-built pure JS with zero third-party dependencies and full v1-40 support.

