canvas 2d selectQuery 后 exec 真机不执行回调
发布于 7 年前 作者 zengming 2613 次浏览 来自 官方Issues
<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))
      })
  })
}
1 回复
wx:show="{{false}}"去掉这个看下?
回到顶部