通过wx.createSelectorQuery()获取到node,然后canvas.getContext(‘2d’).draw()是undefined,而wx.canvasToTempFilePath的文档里写的在 draw() 回调里调用该方法才能保证图片导出成功,在不使用draw直接导出时会报错canvasToTempFilePath: fail canvas is empty。
wxml代码:<canvas canvas-id="canvas" id="canvas" type="2d"></canvas>
基础库:2.20.2
https://developers.weixin.qq.com/s/nXxdzJmV7gvG
ctx.draw 是旧的写法,canvas 2d 上没有这个方法,
https://developers.weixin.qq.com/community/develop/article/doc/000ac686c5c5506f18b87ee825b013