canvas 2d selectQuery 后 exec 真机不执行回调
<canvas wx:show="{{false}}" type="2d" id="canvasForHardwarePrint"></canvas>
script:
getCanvasPrint () {
return new Promise((resolve, reject) => {
const query = wx.createSelectorQuery()
query.select('#canvasForHardwarePrint').fields({ node: true, size: true }).exec((res) => {
// 真机上这个回调不会执行
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr)
ctx.fillRect(0, 0, 1, 1)
let imageData = ctx.createImageData(1, 1)
const base64 = wx.arrayBufferToBase64(imageData.data)
resolve(hashCode(base64))
})
})
}