常用的二维码生成库
https://github.com/soldair/node-qrcode
安装:
npm install --save qrcode
使用:
// index.js -> bundle.js
var QRCode = require("qrcode");
var canvas = document.getElementById("canvas");
QRCode.toCanvas(
canvas,
"http://bing.com/",
{
width: 122,
margin: 0,
},
function (error) {
if (error) console.error(error);
console.log("success!");
}
);
设置“错误更正级别”,越高二维码越复杂:
- L (Low) ~7%
- M (Medium) ~15% 默认值
- Q (Quartile) ~25%
- H (High) ~30%
QRCode.toDataURL(
"some text",
{ errorCorrectionLevel: "H" },
function (err, url) {
console.log(url);
}
);