vue-qr 一款好用的二维码生成工具介绍及使用记录

需求:需要在web项目中为用户生成二维码,然后供用户扫描跳转进入小程序绑定。我们的项目使用Vue框架搭建的,经过调研最后选择用 vue-qr 这款插件来生成二维码,这里记录一下开发流程。

特殊提示:Not support IE 不支持IE浏览器 (需要支持IE的请绕道走)

npm: https://www.npmjs.com/package/vue-qr

git: https://github.com/Binaryify/vue-qr

安装方式

npm install vue-qr --save

引用方式

import VueQr from 'vue-qr'

new Vue({
    components: {VueQr}
})

使用方式

<template>
    <div class="qrcode">
        <vue-qr
           :text="text"
        />
    </div>
</template>
<script>
import VueQr from 'vue-qr'

export default {
    name: 'QrCode',
    components: {
        VueQr
    },
    data() {
        return{
            text:'测试内容'
        }
    },
}
</script>

 只要填写text参数基本上就可以显示一个正常标准的二维码,text: 代表二维码的生成信息,编码的内容。如果二维码要改变颜色或者嵌入背景图片,可以参考一下参数自行搭配:

其他参数

ParameterExplanation
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
colorDarkColor of "true" blocks. Works only when both colorDark and colorLight are set. (BYTE_DTA, BYTE_POS, BYTE_AGN, BYTE_TMG) 实点的颜色
colorLightColor of empty space, or "false" blocks. Works only when both colorDark and colorLight are set. (BYTE_EPT) 空白区的颜色
bgSrcBackground url to embed in the QR code. 欲嵌入的背景图地址
gifBgSrcGif background url to embed in the QR code, If gifBackground is set, backgroundImage will be ignored. This option will affects performance. 欲嵌入的背景图 gif 地址,设置后普通的背景图将失效。设置此选项会影响性能
backgroundColorBackground color 背景色
backgroundDimmingColor mask to add above the background image. Helpful when having problems with decoding. 叠加在背景图上的颜色, 在解码有难度的时有一定帮助
logoSrcLogo url to embed at the center of generated QR code 嵌入至二维码中心的 LOGO 地址
logoScaleValue used to scale the logo image. Larger value may result in decode failure. Size of the logo equals to logoScale*(size-2*margin). 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
logoBackgroundColorLogo 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 0.35 数据区域点缩小比例,默认为0.35
autoColorIf set to true, the dominant color of backgroundImage will be used as colorDark. Default is true. 若为 true, 背景图的主要颜色将作为实点的颜色, 即 colorDark,默认 true
binarizeIf set to true, the whole image will be binarized with the given threshold, or default threshold if not specified. Default is false. 若为 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

根据自己的场景可以去搭配不同参数,生成相对应的颜色以及样式的二维码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值