Qrcode
QR code component drawn with the canvas 2d API (a self-contained pure-JS encoder encodeQrcode plus the canvas sink drawQrcodeToCanvas from share core, identical on web and mini-programs), with no third-party dependencies. Serves URL sharing, credential display, asset tags and similar scenarios.
Platform differences (registered): this port uses the canvas 2d form — mini-program templates cannot render SVG (the share qrcode SVG styles target the web port), so this port consumes the same share-core encoding and drawing pure functions via
<canvas type="2d">; encoding (UTF-8 byte mode, Reed-Solomon error correction, mask selection, full version 1-40 support) all reuses share core; the port only fetches the canvas context and schedules redraws. An emptyvalueor oversized text degrades to an empty state (cleared canvas plus a console warning; the view layer never throws). The component is event-free, slot-free and fully controlled.
Basic usage
<template>
<lh-qrcode value="https://www.lhgb.top" />
</template>Size and error correction level
size is the canvas edge length in px (120 by default); level is the error correction level — higher levels carry more redundancy and recover more damage:
<lh-qrcode value="lh-ui" :size="80" />
<lh-qrcode value="lh-ui" :size="160" level="H" />Version and quiet zone
version ranges 1-40 (0 = automatically pick the smallest version that fits); margin is the quiet zone size in modules (4 by default, the spec minimum):
<lh-qrcode value="lh-ui" :version="5" />
<lh-qrcode value="lh-ui" :margin="1" />
<lh-qrcode value="lh-ui" :version="2" :margin="0" />Custom colors
color is the module foreground color and bgColor the background (token fallback colors when omitted; canvas cannot consume var(--lh-*) strings):
<lh-qrcode value="https://www.lhgb.top" color="#B87800" bg-color="#F5F3EE" />
<lh-qrcode value="https://www.lhgb.top" color="#FFFFFF" bg-color="#2B4C7C" />Chinese and long text
Encoding uses UTF-8 byte mode and supports Chinese; when the content exceeds capacity (1273 bytes at v40-H), the component guards with try/catch and degrades to an empty state:
<lh-qrcode value=" lh-ui · 琉璃瓦组件库 " />Props
| Prop | Description | Type | Default |
|---|---|---|---|
| value | Text to encode (UTF-8, Chinese supported; empty string is the empty state) | string | '' |
| level | Error correction level | 'L' | 'M' | 'Q' | 'H' | 'M' |
| version | Version 1-40 (0 = smallest fitting version picked automatically) | number | 0 |
| margin | Quiet zone size in modules (spec minimum 4) | number | 4 |
| color | Foreground color (module color) | string | body color fallback |
| bgColor | Background color | string | background color fallback |
| size | Size in px (canvas width and height) | number | 120 |
| customClass | Custom class (forwarded to the root node) | string | — |
| sx | sx quick layout props | LhSxProps | — |
Accessibility
The root node carries the role="img" semantics and aria-label defaults to the encoded text (falling back to a generic name when empty), so screen readers can announce the content directly.

