QRCode 二维码

QRCode 二维码

能够将文本转换生成二维码的组件,支持自定义配色和 Logo 配置。

导入

import { QRCode } from "@reglow/reui";

何时使用

当需要将文本转换成为二维码时使用。

代码演示

基础用法

<script setup lang="ts">
import { ref } from 'vue'
import { QRCode } from '@reglow/reui'

const text = ref('https://ant.design/')
</script>

<template>
  <QRCode :value="text" />
</template>
<template>
  <QRCode
    error-level="H"
    value="https://ant.design/"
    icon="/logo.png"
    :icon-size="40"
  />
</template>

渲染类型

支持 canvas 和 svg 两种渲染方式。

<template>
  <QRCode type="canvas" value="https://ant.design/" />
  <QRCode type="svg" value="https://ant.design/" />
</template>

自定义尺寸

<template>
  <QRCode :size="200" value="https://ant.design/" />
</template>

自定义颜色

<template>
  <QRCode value="https://ant.design/" color="#1677ff" />
  <QRCode value="https://ant.design/" color="#52c41a" bg-color="#f6ffed" />
</template>

纠错等级

<template>
  <QRCode value="https://ant.design/" error-level="L" />
  <QRCode value="https://ant.design/" error-level="M" />
  <QRCode value="https://ant.design/" error-level="Q" />
  <QRCode value="https://ant.design/" error-level="H" />
</template>

不同状态

<script setup lang="ts">
import { QRCode } from '@reglow/reui'

const handleRefresh = () => {
  console.log('refresh')
}
</script>

<template>
  <QRCode value="https://ant.design" status="loading" />
  <QRCode value="https://ant.design" status="expired" @refresh="handleRefresh" />
  <QRCode value="https://ant.design" status="scanned" />
</template>

下载二维码

<script setup lang="ts">
import { ref } from 'vue'
import { QRCode } from '@reglow/reui'

const qrRef = ref()
</script>

<template>
  <QRCode ref="qrRef" value="https://ant.design/" />
  <button @click="qrRef?.download()">下载</button>
</template>

API

QRCode Props

参数说明类型默认值
value扫描后的文本string-
type渲染类型'canvas' | 'svg''canvas'
size二维码大小number160
icon中间图片地址string-
iconSize图片大小number | { width: number; height: number }size/4
color二维码颜色string'#000000'
bgColor背景颜色string'transparent'
bordered是否有边框booleantrue
errorLevel纠错等级'L' | 'M' | 'Q' | 'H''M'
marginSize留白大小(模块数)number0
status状态'active' | 'expired' | 'loading' | 'scanned''active'

QRCode Events

事件名说明回调参数
refresh过期状态点击刷新-

QRCode Slots

插槽名说明参数
status自定义状态渲染{ status: string }
loading自定义加载状态-
expired自定义过期状态-
scanned自定义已扫描状态-

QRCode Methods (通过 ref 调用)

方法名说明
download()下载二维码(PNG 或 SVG)

纠错等级说明

等级可纠正错误率
L约 7%
M约 15%
Q约 25%
H约 30%