Skip to content

14 如何生成带图片二维码

孙正华 edited this page Jul 26, 2018 · 2 revisions

安装:

$ npm install --save git+https://github.com/lrsjng/jquery-qrcode.git

页面引用:

https://github.com/eshengsky/iBlog2/blob/master/views/blog/article.pug#L100

script(type='text/javascript', src='/static/jquery-qrcode/dist/jquery-qrcode.min.js', charset='utf-8')

定义二维码容器:

https://github.com/eshengsky/iBlog2/blob/master/views/shared/top.pug#L23

#qrcode

脚本调用:

https://github.com/eshengsky/iBlog2/blob/master/public/js/top.js#L58-L70

img = document.createElement("img");
img.src = logoPath;
img.onload = function () {
    $("#qrcode").qrcode({
        text: window.location.href,
        size: "100",
        ecLevel: 'H',
        minVersion: 4,
        mode: 4,
        image: img,
        mSize: 0.3
    });
};