错误信息如下:
"[Component] <canvas>: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0." "Error: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.\n at l.<anonymous> (about:blank:1:1222184)\n at Generator.next (<anonymous>)\n at n (about:blank:1:2550)\n at s (about:blank:1:2753)"
【抱歉大家,我已经解决了,发布出来分享一下解决思路】
我的代码中canvas绘图逻辑和canvasToTempFilePath都在一个方法里,走到canvasToTempFilePath就报上面的错误(只在pc端出现),查了很久发现下面这种错误经常会在绘图逻辑中图片尚未加载完成就作为参数提供给绘图接口导致的:
The image argument is a canvas element with a width or height of 0.
因此,我在wx.canvasToTempFilePath这个接口调用处加了一层setTimeout,报错就消失了。
我加$nextTick和setTimeout都没有效果,还是报这个错误