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

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

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

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

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}}`  //二维码保存内容
        })

具体参数看文档吧~

猜你喜欢

转载自www.cnblogs.com/milo-wjh/p/9179390.html