node.js 生成二维码

Posted Mr丶Lee

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node.js 生成二维码相关的知识,希望对你有一定的参考价值。

  

  因为自己的项目中,想在商品详情页上 显示一个 商品优惠券的二维码。 以此为需求。

 

 

node.js 后台代码  

const qr_image = require("qr-image");

 

app.get("/qrcode/txt", async (req, res, next) => {
    const temp_qrcode = qr_image.image(req.query.text);
    res.type("png");
    temp_qrcode.pipe(res);
});

 

前端代码。 <img src="" /> src中的路径 是请求后台生成二维码的接口路径

<img
 id="codeimg"
 src="http://localhost/qrcode/txt?text=http://www.baidu.com"
 width="160"
 height="160"
/>

  

 

以上是关于node.js 生成二维码的主要内容,如果未能解决你的问题,请参考以下文章