wxml
<view class="erweima">
<canvas class='erimg' canvas-id='canvas' style="width:{{code_w}}px; height:{{code_w}}px;"></canvas>
</view>
<button>点击生成二维码</button>
js
var QRCode = require('../../utils/weapp-qrcode.js') //引入weapp-qrcode.js
var qrcode;
const W = wx.getSystemInfoSync().windowWidth;
const rate = 750.0 / W;
var colorDark="#000"
// 280rpx 在6s上为 140px
const code_w = 280 / rate;
Page({
data:{
code_w: code_w,
consume:''
}
onLoad: function (options) {
let _this=this
qrcode = new QRCode('canvas', {
text: _this.data.consume, //需要生成二维码的字符串或链接
width: code_w,
height: code_w,
colorDark:"#000",
colorLight: "white",
correctLevel: QRCode.CorrectLevel.H,
});
},
//点击生成二维码
button:function(){
this.setData({
consume: '12345678'
})
qrcode.makeCode(consume)
}
})