1、推荐2个生成二维码的插件包

一、qrcodejs2

QRCode.js是用于制作QRCode的javascript库。QRCode.js支持跨浏览器,在DOM中使用HTML5 Canvas和表标签。 QRCode.js没有依赖关系。

下载
npm 下载
npm i qrcodejs2
yarn 下载
yarn add qrcodejs2
使用方式
<template>
  <div ref="box"></div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import QRCode from 'qrcodejs2'
let box = ref<HTMLDivElement>()
onMounted(() => {
   getCode()
})
 const getCode = () => {
   const qrcode = new QRCode(box.value, {
     text: '二维码展示的内容', // 用于生成二维码的文本
     width: 200, // 高度
     height: 200, // 宽度
     colorDark: '#000000', //前景色
     colorLight: '#ffffff', //后景色
     correctLevel: QRCode.CorrectLevel.H //容错级别 QRCode.CorrectLevel.L QRCode.CorrectLevel.M QRCode.CorrectLevel.Q QRCode.CorrectLevel.H
   })
 }
</script>
二、vue-qr

Vue 唯一的一个二维码组件

下载
npm 下载
npm install vue-qr
yarn 下载
yarn add vue-qr
使用
<vue-qr :bgSrc='src' :logoSrc="src2" text="Hello world!" :size="200"></vue-qr>
<vue-qr text="Hello world!" :callback="test" qid="testid"></vue-qr>
// vue2.0
import VueQr from 'vue-qr'

// vue3.0 (support vite)
import vueQr from 'vue-qr/src/packages/vue-qr.vue'
...
{
  components: {VueQr}
}
属性
参数解释
textContents to encode. 欲编码的内容
correctLevelCorrect Level 0-3 容错级别 0-3
sizeWidth as well as the height of the output QR code, includes margin. 尺寸, 长宽一致, 包含外边距
marginMargin to add around the QR code, default 20px. 二维码图像的外边距, 默认 20px
colorDark“真实”块的颜色。仅当同时设置了颜色深色和颜色浅色时才有效。(BYTE_DTA, BYTE_POS, BYTE_AGN, BYTE_TMG) 实点的颜色
colorLight空白区域或“假”块的颜色。仅当同时设置了颜色深色和颜色浅色时才有效。(BYTE_EPT) 空白区的颜色
components控制 QR 码中零件的外观。阅读组件选项部分以了解更多信息。阅读 ComponentOptions 了解更多信息。
bgSrcBackground url to embed in the QR code. 欲嵌入的背景图地址
gifBgSrc欲嵌入的背景图 gif 地址,设置后普通的背景图将失效。设置此选项会影响性能
backgroundColorBackground color 背景色
backgroundDimming叠加在背景图上的颜色, 在解码有难度的时有一定帮助
logoSrc嵌入至二维码中心的 LOGO 地址
logoScaleValue used to scale the logo image. Larger value may result in decode failure. Size of the logo equals to logoScale*(size-2margin). Default is 0.2. 用于计算 LOGO 大小的值, 过大将导致解码失败, LOGO 尺寸计算公式 logoScale(size-2*margin), 默认 0.2
logoMarginWhite margin that appears around the logo image. Default is 0. LOGO 标识周围的空白边框, 默认为0
logoBackgroundColor 徽标背景颜色Logo background color, need set logo margin. Logo 背景色,需要设置 logo margin
logoCornerRadiusRadius of the logo’s corners.Default is 0 LOGO 标识及其边框的圆角半径, 默认为0
whiteMarginIf set to true, a white border will appear around the background image. Default is true. 若设为 true, 背景图外将绘制白色边框
dotScaleValue used to scale down the data dots’ size. (0 < scale < 1.0) default 1 数据区域点缩小比例,默认为1
autoColor若为 true, 背景图的主要颜色将作为实点的颜色, 即 colorDark,默认 true
binarize若为 true, 图像将被二值化处理, 未指定阈值则使用默认值
binarizeThresholdThreshold used to binarize the whole image. Default is 128. (0 < threshold < 255) 二值化处理的阈值
callbackData URI of the generated QR code will be available here. 生成的二维码 Data URI 可以在回调中取得,第一个参数为二维码 data URL, 第二个参数为 props 传过来的 qid(因为二维码生成是异步的,所以加个 id 用于排序)
bindElementIf set to true, the generated QR will bind to a HTML element automatically. Default is true. 指定是否需要自动将生成的二维码绑定到HTML上, 默认是true
Logo

前往低代码交流专区

更多推荐