Draw回调加延时换成setTimeout就好了,代码如下 [代码]const context = wx.createCanvasContext([代码][代码]'xx_canvas'[代码][代码]);[代码] [代码] [代码][代码]context.setFillStyle([代码][代码]'red'[代码][代码])[代码] [代码] [代码][代码]context.fillRect(10, 10, 150, 100)[代码] [代码] [代码][代码]console.log([代码][代码]"1"[代码][代码]);[代码] [代码] [代码][代码]context.draw([代码][代码]false[代码][代码], setTimeout([代码][代码]function[代码][代码](e) {[代码] [代码] [代码][代码]console.log([代码][代码]"2"[代码][代码]);[代码] [代码] [代码][代码]// do something...[代码] [代码] [代码][代码]wx.canvasToTempFilePath({[代码] [代码] [代码][代码]x: 0,[代码] [代码] [代码][代码]y: 0,[代码] [代码] [代码][代码]width: 650,[代码] [代码] [代码][代码]height: 960,[代码] [代码] [代码][代码]canvasId: [代码][代码]'xx_canvas'[代码][代码],[代码] [代码] [代码][代码]fileType: [代码][代码]'png'[代码][代码],[代码] [代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码] [代码] [代码][代码]let pic = res.tempFilePath;[代码] [代码] [代码][代码]console.log(pic);[代码] [代码] [代码][代码]wx.previewImage({[代码] [代码] [代码][代码]urls: [res.tempFilePath],[代码] [代码] [代码][代码]})[代码] [代码] [代码][代码]}[代码] [代码] [代码][代码]});[代码] [代码] [代码][代码]},300))[代码]
Component中canvas的draw回调函数无法进入- 当前 Bug 的表现(可附上截图) Component中canvas的draw回调函数无法进入, 只打印了1 - 预期表现 回调函数会进入,并打印1 和 2 - 复现路径 见Demo - 提供一个最简复现 Demo const context = wx.createCanvasContext('xx_canvas'); context.setFillStyle('red') context.fillRect(10, 10, 150, 100) console.log("1"); context.draw(false, function(e) { console.log("2"); // do something... wx.canvasToTempFilePath({ x: 0, y: 0, width: 650, height: 960, canvasId: 'xx_canvas', fileType: 'png', success: function (res) { let pic = res.tempFilePath; console.log(pic); wx.previewImage({ urls: [res.tempFilePath], }) } }); }) 只打印了“1”,未打印2.
2019-01-07