在小程序页面生成二维码,先看下目录结构,除了四个必备文件之外,引入了三个文件
一个是条形码,一个是二维码
在.js文件中引入配置
function barc(id, code, width, height){
barcode.code128(my.createCanvasContext(id), code, convert_length(width), convert_length(height))
}
function qrc(id, code, width, height) {
qrcode.api.draw(code, {
ctx: my.createCanvasContext(id),
convert_length(width),
height: convert_length(height)
})
}
function convert_length(length) {
return Math.round(my.getSystemInfoSync().windowWidth * length / 750);
}
var wxbarcode = require('./index.js');
code中是二维码的信息,自己根据需要去修改
在axml中展示,如果code中信息改变要重新调用onShow函数