vue:生成二维码 qrcode、vue-qr(二维码中间可带logo)

news/2024/10/18 7:52:01/

一、方法一 qrcode

qrcode - npm

1.1、安装

yarn add qrcode

1.2、页面引入

import QRCode from 'qrcode';

1.3、方法里边使用

getQRCodeUrl(){  QRCode.toDataURL('hello world',{color: {dark:"#010599FF",light:"#FFBF60FF"}}).then((url) => {// 获取到url后即可在页面使用--二维码图片console.log('url', url)}).catch((e) => {console.log('e', e)});
}

 二维码url:

​​​​​​​ 

1.4、options

名称类型默认值说明
errorCorrectionLevelStringM错误处理级别。可选值:lowmediumquartilehigh or LMQH
maskPatternNumber可选值:01234567
marginNumber4
scaleNumber4
widthNumber
color.darkString#000000ff
color.lightString#ffffffff

二、方法二 vue-qr

vue-qr - npm

2.1、安装

yarn add vue-qr

2.2、页面引入

import VueQr from 'vue-qr'

2.3、组件增加vue-qr

components: { VueQr },

2.4、template使用

logoSrc中间logo

<vue-qr style="width:200px;height:200px;" logoSrc="https://image.dandelioncloud.cn//dist/img/NoSlightly.png" text="Hello world!" :size="200"></vue-qr>

 2.5、options

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) 空白区的颜色
componentsControls the appearances of parts in the QR code. Read section ComponentOptions to learn more. 阅读 ComponentOptions 了解更多信息。
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 1 数据区域点缩小比例,默认为1
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

三、欢迎交流指正,关注我一起学习


http://www.ppmy.cn/news/47212.html

相关文章

循环结构化命令小结

shell脚本编程系列 循环是编程不可或缺的一部分。bash shell提供了三种循环命令。 for命令允许遍历一系列的值&#xff0c;无论是在命令行中提供的&#xff0c;还是包含在变量中的&#xff0c;或是通过文件名通配符匹配获得的文件名和目录名。 for var in list docommands do…

MySQL索引数据结构入门

之前松哥写过一个 MySQL 系列&#xff0c;但是当时是基于 MySQL5.7 的&#xff0c;最近有空在看 MySQL8 的文档&#xff0c;发现和 MySQL5.7 相比还是有不少变化&#xff0c;同时 MySQL 又是小伙伴们在面试时一个非常重要的知识点&#xff0c;因此松哥打算最近再抽空和小伙伴们…

在React中使用setState修改数组的值时,为什么不能使用数组的可变方法(push、unshift等)? 但在vue中可以

一、为什么React中修改数组时不能使用数组的可变方法 在React中使用setState修改数组的值时&#xff0c;不推荐使用数组的可变方法&#xff08;如push、unshift等&#xff09;。这是因为React会对比新旧状态&#xff0c;在发现状态变化后&#xff0c;更新组件的渲染。但当你调…

TiDB实战篇-TiDB Cluster部署

简介 部署TiDB Cluster部署&#xff0c;熟系集群的基础操作。 集群规划 机器拓扑 3pd,3tikv,1tidb_server.1tiflash,监控。 192.168.66.10192.168.66.20192.168.66.21 pd_servers tikv_servers tidb_servers tiflash_servers pd_servers tikv_servers monitoring_servers…

SSH升级

升级openssh版本 一、安装telnet远程管理主机1、检查是否安装telnet2、安装telnet服务 二、下载所需的安装包1、下载openssl、openssh、zlib安装包2、安装所需的相关软件3、备份原来的数据4、复制文件到/usr/local/bin/下增加执行权限 一、安装telnet远程管理主机 1、检查是否…

用SQL语句操作Oracle数据库--数据查询详解(下篇)

数据查询是数据库的核心操作。上一篇文章我们介绍了单表查询操作&#xff0c;本文将继续介绍另一种重要的查询类型—[ 多表查询 ]&#xff08;涉及多个表的数据查询&#xff09;。 本文我们将使用以下三个表来进行查询操作&#xff1a; TABLE1: S(学生基本信息表) TABLE2: C(…

设置Pycharm的背景颜色(样式)、图片

目录 一、效果 二、背景图片 三、背景颜色 一、效果 二、背景图片 1.打开Pycharm中的File-Settings 2.点击Appearance & Behavior中的Appearance&#xff0c;然后点击Bcakground Image &#xff08;图中已标明顺序&#xff09; 3.找到图片并选中。 &#xff08;图中已…

需要买apple pencil吗?ipad第三方电容笔了解下

第一款ipad早在诞生于十年前&#xff0c;并被作为一款平板电脑使用&#xff0c;其性能十分出色。随着IPAD的不断更新换代&#xff0c;IPAD已经被越来越多的人接受了。其中&#xff0c;iPad的附属配件起到了很大的作用&#xff0c;就像今天要介绍的电容笔&#xff0c;它是我们进…