急急急!求解答!自定义组件中调用canvasToTempFilePath提示为空?
在自定义组件中调用canvasToTempFilePath,提示canvasToTempFilePath: fail canvas is empty
wx.canvasToTempFilePath(Object object, Object this)
wx.createCanvasContext(string canvasId, Object this)
这两个方法第二个参数已经写了this,
const ctx = wx.createCanvasContext('sku-bill-canvas', that);
....
...
ctx.draw(false, setTimeout(() => {
console.log(3)
//生成分享图
wx.canvasToTempFilePath({
canvasId: 'sku-bill-canvas',
success: function (res) {
console.info(res.tempFilePath)
that.setData({
skuBillPreUrl: res.tempFilePath,
showCanvas: false
})
//海报预览图
app.globalData.skuBillPreUrl = res.tempFilePath
console.info('skuBillPreUrl:' + that.data.skuBillPreUrl)
}, fail: function (res) {
console.info(res);
}
}, this)
}, 300))
4 回复
画布标识,传入 canvas 组件的 canvas-id。要不你就设置width,height为0或者不显示了
你忘记设置<canvas canvas-id="sku-bill-canvas"
了。而是设置 id="sku-bill-canvas"了?