Skip to content

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 empty value or 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 ​

vue
<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:

vue
<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):

vue
<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):

vue
<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:

vue
<lh-qrcode value=" lh-ui · 琉璃瓦组件库 " />

Props ​

PropDescriptionTypeDefault
valueText to encode (UTF-8, Chinese supported; empty string is the empty state)string''
levelError correction level'L' | 'M' | 'Q' | 'H''M'
versionVersion 1-40 (0 = smallest fitting version picked automatically)number0
marginQuiet zone size in modules (spec minimum 4)number4
colorForeground color (module color)stringbody color fallback
bgColorBackground colorstringbackground color fallback
sizeSize in px (canvas width and height)number120
customClassCustom class (forwarded to the root node)string—
sxsx quick layout propsLhSxProps—

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.