vue项目条形码和二维码生成工具试用

项目开发须要,优惠券分不一样类型,简单的使用id生成条形码供店铺使用,麻烦点的须要多个字段的就须要使用二维码来展现了,对应的效果以下

css

条形码(一维码)使用工具code128

需引入code128.js 和对应的 code123.css, 具体代码能够看 https://www.jb51.net/article/103472.htm
因为项目是vue开发,因此code128.js 稍微改一下,export 出createBarcode接口vue

export default function createBarcode(showDiv,textValue,barcodeType){
  var divElement = document.getElementById(showDiv);
    divElement.innerHTML = code128(textValue,barcodeType);
}
import createBarcode from '@/utils/code128'
调用:
createBarcode("barcodeDiv", this.couponInfo.data.id, 'B', true)

二维码 使用工具 qrcodejs2

npm install qrcodejs2 --save

调用
import QRCode from 'qrcodejs2'
new QRCode(document.getElementById('qrcode'), {
          width: 120,
          height: 120,
          text: `{"customeruid":${this.couponInfo.data.customerUid}, "shoppingcarduid": ${this.couponInfo.data.UId}}`  //二维码保存内容
        })

具体参数看文档吧~npm

相关文章
相关标签/搜索