1.前端代码
<img src="http://127.0.0.1:8888" alt=""/>
2.后台代码
var http=require("http") var qr=require('qr-image') var app=http.createServer(function(req,res){ var img = qr.image("https://www.baidu.com",{size :10});//编码网址和图片大小这个是 330*330入写size:20则是660*660 res.writeHead(200,{'content-Type':"image/png","Access-Control-Allow-Origin":"*"}) img.pipe(res); //这后面一定不能写res.end()否则就显示不出来图片 }) app.listen(8888,function(){ console.log("server is running") })例子2:
前端代码:
<img src="/create_qrcode?text=http://blog.csdn.net/fo11ower"/>
后台代码:
router.get('/create_qrcode', function (req, res, next) { var text = req.query.text; var img = qr.image(text,{size :10}); res.writeHead(200, {'Content-Type': 'image/png'}); img.pipe(res); }) //这样写的思路清晰可以借鉴