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"
/>
相關文章
相關標籤/搜索