• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

使用 qrcodejs2 生成二维码详细API和参数

武飞扬头像
_格鲁特宝宝
帮助5

使用 qrcodejs2 生成二维码

安装 qrcodejs2

cnpm install qrcodejs2 --save

使用 qrcodejs2

页面引入

import QRCode from 'qrcodejs2'

页面标签

<div id="qrcode" ref="qrcode"></div>

可以使⽤ id 或者 ref,建议使⽤ ref,因为使⽤ vue 框架控制虚拟 Dom 才是正确的选择简单⽅便

  1.  
    createQRcode(WIDTH, id, text) {
  2.  
    // 重复创建二维码会,之前的二维码还在,新创建的会被接在下面
  3.  
    // 此行代码是为了解决以上问题 或者 刷新二维码的时候生成多个二维码的问题
  4.  
    if(this.$refs.qrcode) this.$refs.qrcode.innerHTML = ""
  5.  
    let long = document.documentElement.clientWidth * (WIDTH / 375)
  6.  
    new QRCode(id, {
  7.  
    width: long,
  8.  
    height: long,
  9.  
    text: text,
  10.  
    correctLevel : QRCode.CorrectLevel.L
  11.  
    });
  12.  
    // correctLevel 容错级别,可设置为:
  13.  
    // QRCode.CorrectLevel.L
  14.  
    // QRCode.CorrectLevel.M
  15.  
    // QRCode.CorrectLevel.Q
  16.  
    // QRCode.CorrectLevel.H
  17.  
    // L - M - Q - H 码密度越来越高,默认不设置是用 H
  18.  
    },
  19.  
    // this.createQRcode(132, `qrcode`, `${this.DOMAIN}`);
学新通

参数说明

new QRCode(element, option)
名称 默认值 说明
element - 显示二维码的元素或该元素的 ID
option   参数配置

Options

名称 默认值 说明
width 256 图像宽度
height 256 图像高度
typeNumber 4  
colorDark "#000000" 前景色
colorLight "#ffffff" 背景色
correctLevel QRCode.CorrectLevel.L

容错级别,可设置为:

QRCode.CorrectLevel.L

QRCode.CorrectLevel.M

QRCode.CorrectLevel.Q

QRCode.CorrectLevel.H

从上至下生成码密度越来越高

L - M - Q - H

Events

名称 说明
makeCode(text) 设置二维码内容
clear() 清除二维码。(仅在不支持 Canvas 的浏览器下有效)

资源 

qrcodejs2 - npmJavsacript QRCode for all browsers. Latest version: 0.0.2, last published: 7 years ago. Start using qrcodejs2 in your project by running `npm i qrcodejs2`. There are 166 other projects in the npm registry using qrcodejs2.学新通https://www.npmjs.com/package/qrcodejs2

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfhkjeg
系列文章
更多 icon
同类精品
更多 icon
继续加载