github官方文檔指路:https://github.com/soldair/node-qrcode#options
QRcode方法介紹:
這里只介紹后三種常用方法的使用:
1、toCanvas 顧名思義是講二維碼生成canvas
用法實例:
//1、引入QRcode.js
<script src='qrcode.js'></script>
//2、具體用法
QRCode.toCanvas('二維碼信息文本', {
errorCorrectionLevel: "L",//容錯率L(低)H(高)
margin: 1,//二維碼內邊距,默認為4。單位px
height: 200,//二維碼高度
width: 200,//二維碼寬度
scal: 177,
color: {
dark: '#000', // 二維碼背景顏色
// light: '#000' // 二維碼前景顏色
},
rendererOpts: {
quality: 0.9
}
}).then(canvas => {
console.log(canvas)
document.getElementById('myqrcode').append(canvas)
}).catch((err) => {
console.log(err)
})
背景和前景顏色不可以相近,不然有的設備上會識別不出來二維碼
2、toDataURL()生成base64字符串
用法實例:
QRCode.toDataURL('sss', {
errorCorrectionLevel: "L",
margin: 1,
height: 200,
width: 200,
type: "10",
scal: 177,
type: "10",
color: {
dark: '#000', // 二維碼背景顏色
// light: '#000' // 二維碼前景顏色
},
rendererOpts: {
quality: 0.9
}
}).then(base64 => {
console.log(base64);//base64字符串
}).catch((err) => {
console.log(err)
})
3、toString()生成svg二進制字符
QRCode.toString('sss', {
errorCorrectionLevel: "L",
margin: 1,
height: 200,
width: 200,
type: "10",
scal: 177,
type: "10",
color: {
dark: '#000', // 二維碼背景顏色
// light: '#000' // 二維碼前景顏色
},
rendererOpts: {
quality: 0.9
}
}).then(canvas => {
console.log(canvas)
document.getElementById('myqrcode').append(canvas)
}).catch((err) => {
console.log(err)
})