canvas绘制二维码
一、导入绘制依赖的文件
二、在wxml中写入canvas标签
id、canvas-id不要丢
<canvas class="codeContent" canvas-id="qrcode" id="qrcode"></canvas>
三、在js文件中引入依赖
import mycode from '../../../utils/weapp.qrcode'
四、绘制二维码的方法
// 绘制二维码
drawCode() {
wx.createSelectorQuery().select('#qrcode').fields({
node: true,
size: true
}).exec((res) => {
console.log(res);
let {
width,
height
} = res[0]
console.log("绘制", this.data.code);
mycode({
width: width,
height: height,
x: 0,
y: 0,
canvasId: 'qrcode',
text: this.data.code,
})
})
},