data: {
canvasId: '',
QRdata: '你好 wxmp-qrcode'
},
creatQRCode () {
this.setData({canvasId: Date.now()})
const query = wx.createSelectorQuery()
query.select('#' + this.data.canvasId)
.fields({
node: true,
size: true
})
.exec(async (res) => {
console.log('22222222222',res)
var canvas = res[0].node
console.log('333333333333')
await drawQrcode({
canvas: canvas,
canvasId: this.data.canvasId,
width: 260,
padding: 30,
background: '#ffffff',
foreground: '#000000',
text: 'https://www.baidu.com/?tn=15007414_11_dg',
})
})
<canvas type="2d" style="width: 260px; height: 260px;" id="{{canvasId}}"></canvas>
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
你看一下这个this指向对吗?改成外边定义that试试