1. 程式人生 > >vue項目條形碼和二維碼生成工具試用

vue項目條形碼和二維碼生成工具試用

def info 接口 eight width ppi PE port image

項目開發需要,優惠券分不同類型,簡單的使用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}}`  //二維碼保存內容
        })

具體參數看文檔吧~

vue項目條形碼和二維碼生成工具試用