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"
/>

  

猜你喜欢

转载自www.cnblogs.com/MrLee/p/9588976.html