使用 qrcodejs2 生成二维码
安装 qrcodejs2
cnpm install qrcodejs2 --save
使用 qrcodejs2
页面引入
import QRCode from 'qrcodejs2'
页面标签
<div id="qrcode" ref="qrcode"></div>
可以使⽤ id 或者 ref,建议使⽤ ref,因为使⽤ vue 框架控制虚拟 Dom 才是正确的选择简单⽅便
createQRcode(WIDTH, id, text) {
// 重复创建二维码会,之前的二维码还在,新创建的会被接在下面
// 此行代码是为了解决以上问题 或者 刷新二维码的时候生成多个二维码的问题
if(this.$refs.qrcode) this.$refs.qrcode.innerHTML = ""
let long = document.documentElement.clientWidth * (WIDTH / 375)
new QRCode(id, {
width: long,
height: long,
text: text,
correctLevel : QRCode.CorrectLevel.L
});
// correctLevel 容错级别,可设置为:
// QRCode.CorrectLevel.L
// QRCode.CorrectLevel.M
// QRCode.CorrectLevel.Q
// QRCod