Skip to content
API 风格:

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

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

Error-correction levels
vue
<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):

Colors and sizes
vue
<LhQrcode :value="text" color="#2B4C7C" :size="140" />
<LhQrcode :value="text" color="#D9393B" bg-color="#FFF7E8" :size="140" />

API ​

Qrcode Props ​

PropDescriptionTypeDefault
valueText to encode (UTF-8, supports Chinese; an empty value renders the empty state)string''
levelError-correction level (L 7% / M 15% / Q 25% / H 30% fault tolerance)'L' | 'M' | 'Q' | 'H''M'
versionVersion 1-40; 0 = automatically pick the smallest version that fitsnumber0
marginQuiet-zone module count (4 by default, the spec minimum)number4
colorModule foreground color (falls back to the lh-qrcode token / a dark color by default when not passed)string—
bgColorBackground color (no background rect drawn when not passed, going through the stylesheet token)string—
sizeRendered pixel sizenumber120
labelAccessible namestring—
sxsx quick-layout propsLhSxProps—

Accessibility ​

  • The root node is role="img"; its accessible name defaults to "QR code" and can be overridden with label
  • 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.warn and degraded to an empty state, never throwing

The encoder is self-built pure JS with zero third-party dependencies and full v1-40 support.

Beauty of tradition, foundation of code