博客
关于我
在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/

    你可能感兴趣的文章
    oracle获取数据库表、字段、注释、约束等
    查看>>
    Oracle计划将ZGC项目提交给OpenJDK
    查看>>
    Oracle闪回技术(Flashback)
    查看>>
    oracle零碎要点---ip地址问题,服务问题,系统默认密码问题
    查看>>
    oracle零碎要点---oracle em的web访问地址忘了
    查看>>
    Oracle零碎要点---多表联合查询,收集数据库基本资料
    查看>>
    Oracle静默安装
    查看>>
    Oracle面试题:Oracle中truncate和delete的区别
    查看>>
    thinkphp 常用SQL执行语句总结
    查看>>
    Oracle:ORA-00911: 无效字符
    查看>>
    Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
    查看>>
    TCP基本入门-简单认识一下什么是TCP
    查看>>
    Orcale表被锁
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
    查看>>
    org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    查看>>
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>