博客
关于我
在vue项目中使用qrcodesjs2生成二维码
阅读量:336 次
发布时间:2019-03-04

本文共 869 字,大约阅读时间需要 2 分钟。

使用 qrcodejs2 生成二维码

安装

npm install qrcodejs2 --save

HTML 配置

JavaScript 实现

// 生成二维码printMultipleQRCode() {  for (let i in this.qrcodeList) {    const qrContainer = this.$refs[`qrcode-${i}`];    if (qrContainer) {      new QRCode(qrContainer[0], {        text: this.qrcodeList[i],        render: 'canvas',        width: 130,        height: 130,        colorDark: '#000000',        colorLight: '#ffffff'      });    }  }},// 清除二维码clearQRCode() {  for (let i in this.qrcodeList) {    const qrContainer = this.$refs[`qrcode-${i}`];    if (qrContainer && qrContainer[0]) {      qrContainer[0].innerHTML = '';    }  }},// 初始化并生成二维码this.$nextTick(() => {  this.printMultipleQRCode();});

说明

  • 安装依赖:使用 npm 安装 qrcodejs2 库以便开始使用
  • HTML 结构:确保有一个容器来渲染多个二维码,使用 v-for 循环处理多个二维码
  • JS 实现:创建用于生成和清除二维码的方法
  • 打印多个二维码:确保代码可以处理多个二维码容器
  • 清除功能:提供清除现有二维码的功能
  • 通过以上方法,您可以在项目中轻松生成并管理多个二维码。

    转载地址:http://megh.baihongyu.com/

    你可能感兴趣的文章
    npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
    查看>>
    npm run build部署到云服务器中的Nginx(图文配置)
    查看>>
    npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
    查看>>
    npm切换到淘宝源
    查看>>
    npm前端包管理工具简介---npm工作笔记001
    查看>>
    npm和yarn清理缓存命令
    查看>>
    npm和yarn的使用对比
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    NPOI之Excel——合并单元格、设置样式、输入公式
    查看>>
    NPOI利用多任务模式分批写入多个Excel
    查看>>
    NR,NF,FNR
    查看>>
    nrf开发笔记一开发软件
    查看>>
    NSDateFormatter的替代方法
    查看>>
    nsis 安装脚本示例(转)
    查看>>
    NSOperation基本操作
    查看>>
    NSSet集合 无序的 不能重复的
    查看>>
    NT AUTHORITY\NETWORK SERVICE 权限问题
    查看>>
    NT symbols are incorrect, please fix symbols
    查看>>
    ntko web firefox跨浏览器插件_深度比较:2019年6个最好的跨浏览器测试工具
    查看>>