Skip to content

Barcode 条码

生成各种格式的条码,支持多种样式和主题。

基础用法

最基本的条码生成。

vue
<template>
  <ex-barcode value="123456789012" />
</template>

条码格式

支持多种常见的条码格式。

CODE128 (默认)

EAN-13 (商品条码)

CODE39

UPC-A

vue
<template>
  <!-- CODE128 (默认) -->
  <ex-barcode value="Hello World" format="CODE128" />

  <!-- EAN-13 (商品条码) -->
  <ex-barcode value="5901234123457" format="EAN13" />

  <!-- CODE39 -->
  <ex-barcode value="CODE39" format="CODE39" />

  <!-- UPC-A -->
  <ex-barcode value="012345678905" format="UPC" />
</template>

自定义尺寸

调整条码的宽度和高度。

小尺寸

中等尺寸 (默认)

大尺寸

vue
<template>
  <!-- 小尺寸 -->
  <ex-barcode value="123456" :width="1" :height="50" />

  <!-- 中等尺寸 (默认) -->
  <ex-barcode value="123456" :width="2" :height="100" />

  <!-- 大尺寸 -->
  <ex-barcode value="123456" :width="3" :height="150" />
</template>

赛博朋克风格

提供霓虹和赛博朋克风格的条码样式。

默认样式

霓虹样式

赛博朋克样式

vue
<template>
  <!-- 默认样式 -->
  <ex-barcode value="DEFAULT123" type="default" />

  <!-- 霓虹样式 -->
  <ex-barcode value="NEON456" type="neon" />

  <!-- 赛博朋克样式 -->
  <ex-barcode value="CYBER2077" type="gaming" />
</template>

自定义颜色

自定义条码的线条颜色和背景颜色。

蓝色条码

粉色条码

绿色条码

vue
<template>
  <!-- 蓝色条码 -->
  <ex-barcode value="BLUE123" line-color="#29abe2" background="#0b0f14" />

  <!-- 粉色条码 -->
  <ex-barcode value="PINK456" line-color="#ff007f" background="#1a0a1e" />

  <!-- 绿色条码 -->
  <ex-barcode value="GREEN789" line-color="#00ff41" background="#000000" />
</template>

文本显示

控制条码下方文本的显示和位置。

显示文本 (默认)

隐藏文本

文本在顶部

自定义字体大小

vue
<template>
  <!-- 显示文本 (默认) -->
  <ex-barcode value="123456" :display-value="true" />

  <!-- 隐藏文本 -->
  <ex-barcode value="123456" :display-value="false" />

  <!-- 文本在顶部 -->
  <ex-barcode value="123456" text-position="top" />

  <!-- 自定义字体大小 -->
  <ex-barcode value="123456" :font-size="24" />
</template>

下载功能

支持下载条码为图片。

vue
<template>
  <div>
    <ex-barcode ref="barcodeRef" value="DOWNLOAD123" />
    <ex-button @click="handleDownload">下载条码</ex-button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const barcodeRef = ref();

const handleDownload = () => {
  barcodeRef.value?.download('my-barcode.png');
};
</script>

API

Props

参数说明类型默认值
value条码值string''
format条码格式BarcodeFormat'CODE128'
width条码宽度number2
height条码高度number100
display-value是否显示文本booleantrue
text-position文本位置'top' / 'bottom''bottom'
text-margin文本边距number2
font-size字体大小number20
font字体string'monospace'
text-align文本对齐'left' / 'center' / 'right''center'
line-color线条颜色string'#000000'
background背景颜色string'#ffffff'
margin边距number10
flat是否平滑booleanfalse
type样式类型'default' / 'neon' / 'gaming' (赛博朋克)'default'
bordered是否显示边框booleantrue
border-radius圆角number8
error-text错误提示文本string
aria-label无障碍标签string

Barcode Format

支持的条码格式:

  • CODE128 - CODE128 (默认,最常用)
  • CODE39 - CODE39
  • EAN13 - EAN-13 (商品条码,13位数字)
  • EAN8 - EAN-8 (8位数字)
  • UPC - UPC-A (12位数字)
  • ITF14 - ITF-14 (14位数字)
  • MSI - MSI
  • pharmacode - Pharmacode
  • codabar - Codabar

Slots

插槽名说明参数
error错误状态插槽

Methods

方法名说明参数
download下载条码(filename?: string)
toDataURL获取条码数据URL(type?: 'image/png' / 'image/jpeg')
refresh刷新条码