微信小程序—条形码展示
条形码js封装 —index.js
var barcode = require('./barcode');
function convert_length(length) {
return Math.round(wx.getSystemInfoSync().windowWidth * length / 750);
}
function barc(id, code, width, height) {
barcode.code128(wx.createCanvasContext(id), code, convert_length(width), convert_length(height))
} module.exports = { barcode: barc }
调用index.js
const app = getApp()
var wxbarcode = require('../../utils/index.js');
barcodes(datas){
var that = this;
wx.showLoading({
title: '条形码加载中',
})
var barcodes = datas
console.log('barcodes:', barcodes)
setTimeout(function () {
wx.hideLoading()
wxbarcode.barcode('barcode', datas, 402, 150); //后面的数字可以控制条形码的粗细显示
}, 2000);
that.setData({
barcodes: barcodes,
})
},