在小程序中引入weapp-qrcode.js,然后在需要转化的页面引入这个js,
var QRCode=require("../../utils/weapp-qrcode.js")
页面wxml
<canvas class='canvas' canvas-id='canvas' bindlongtap='save'></canvas>
开始
var qrcode = new QRCode('canvas', {
text: "123456",
width: 150,
height: 150,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H,
});
text
为需要转化为二维码的字符串;
width
和height
为绘制出的二维码长宽,这里设置为跟canvas
同样的长宽;
colorDark
和colorLight
为二维码交替的两种颜色;
correctLevel
没有细看源码,命名上看应该是准确度;
如果需要再次生成二维码,调用qrcode.makeCode('text you want convert')
。