使用node-qrcode生成二维码
node-qrcode生成二维码
安装
npm install --save qrcode
使用:
一、新建放置二维码的canvas
html
<canvas id="canvas"></canvas>
二、执行QRCode.toCanvas方法
js
QRCode.toCanvas(document.getElementById('canvas'), 'http://127.0.0.1:5173/', {
width: '100'
}).then((res) => {
console.log(res)
})
备注:
toCanvas(canvasElement, text, [options], [cb(error)])
canvasElement要放置二维码的位置,通过document.getElementById获取
text 要渲染成二维码的数据,可以是文字,也可以是Url
options 现在确定是可以传width
cb 生成二维码成功后返回的函数