Skip to content
API 风格:

Barcode ​

Barcode component (web SVG form): the text is encoded into a module bit array by the self-contained pure-JS encoder in @lh-ui/share/core/barcode (encodeBarcode), and barcodeToSvgPath turns it into a bar-module path rendered inside an <svg> (same shape as the Qrcode component). The encoder is self-contained pure JS with zero third-party dependencies: CODE128 (automatic A/B/C subset selection plus a mod 103 check digit) and EAN-13 (12-digit input gets its check digit computed; 13-digit input is validated).

Bar height, quiet zone, foreground / background colors and the human-readable number are all supported. An empty value or an un-encodable input (non-ASCII for CODE128, a mismatched EAN-13 check digit) degrades to an empty state (no svg rendered, console.warn logged) so encoding errors never bubble up to the rendering layer.

Basic Usage ​

value is the content to encode; type selects the symbology (default CODE128):

Basic Usage
LH-UI-20266901234567892
vue
<script setup lang="ts">
import { LhBarcode } from '@lh-ui/vue3'
</script>

<template>
  <!-- Basic usage -->
  <LhBarcode value="LH-UI-2026" show-text />
  <LhBarcode value="690123456789" type="EAN13" show-text />
</template>
vue
<script>
import { LhBarcode } from '@lh-ui/vue3'

export default {
  components: { LhBarcode },
}
</script>

<template>
  <!-- Basic usage -->
  <LhBarcode value="LH-UI-2026" show-text />
  <LhBarcode value="690123456789" type="EAN13" show-text />
</template>

EAN-13: a 12-digit input gets its check digit appended (e.g. 690123456789 becomes 6901234567892); a 13-digit input whose check digit does not match throws and degrades to the empty state.

Height and Quiet Zone ​

height is the bar height in px (default 64); margin is the left/right quiet zone in modules (default 10, the floor for reliable scanning); showText renders the human-readable digits in a monospace face below the bars:

Height and Quiet Zone
ABC-12345ABC-12345
vue
<script setup lang="ts">
import { LhBarcode } from '@lh-ui/vue3'
</script>

<template>
  <!-- Height and quiet zone -->
  <LhBarcode value="ABC-12345" :height="48" :margin="4" show-text />
  <LhBarcode value="ABC-12345" :height="80" :margin="16" show-text />
</template>
vue
<script>
import { LhBarcode } from '@lh-ui/vue3'

export default {
  components: { LhBarcode },
}
</script>

<template>
  <!-- Height and quiet zone -->
  <LhBarcode value="ABC-12345" :height="48" :margin="4" show-text />
  <LhBarcode value="ABC-12345" :height="80" :margin="16" show-text />
</template>

Custom Colors ​

color overrides the bar foreground (falls back to the --lh-text-primary token); bgColor draws a background rect (transparent when omitted, using the stylesheet token):

Colors
8866-20268866-2026
vue
<script setup lang="ts">
import { LhBarcode } from '@lh-ui/vue3'
</script>

<template>
  <!-- Colors -->
  <LhBarcode value="8866-2026" color="#2B4C7C" show-text />
  <LhBarcode value="8866-2026" color="#D9393B" bg-color="#FFF7E8" show-text />
</template>
vue
<script>
import { LhBarcode } from '@lh-ui/vue3'

export default {
  components: { LhBarcode },
}
</script>

<template>
  <!-- Colors -->
  <LhBarcode value="8866-2026" color="#2B4C7C" show-text />
  <LhBarcode value="8866-2026" color="#D9393B" bg-color="#FFF7E8" show-text />
</template>

API ​

Barcode Props ​

PropDescriptionTypeDefault
valueContent to encode (EAN13 takes 12 or 13 digits)string''
typeSymbology'CODE128' | 'EAN13''CODE128'
heightBar height (px)number64
marginLeft/right quiet zone (modules)number10
colorForeground color (bars)string—
bgColorBackground color (spaces)string—
showTextHuman-readable digits under the barsbooleanfalse
labelAccessible name (defaults to "barcode")string—
sxsx quick-layout propsLhSxProps—

Accessibility ​

  • The root carries role="img" with an accessible name defaulting to "barcode", overridable via label
  • The empty state (empty value or encoding failure) renders no svg and leaves no residual nodes in the DOM
  • Encoding failures are logged via console.warn and degrade to the empty state instead of throwing

The encoder is self-contained pure JS (CODE128 / EAN-13 standard data), zero third-party dependencies.

Beauty of tradition, foundation of code