急急急!求解答!自定义组件中调用canvasToTempFilePath提示为空?

发布于 6 年前作者 nren6375 次浏览最后编辑 6 年前来自 issues

在自定义组件中调用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 回复
tangguiying
tangguiying1 楼6 年前

画的图出来了么 先不管生成那一步

yan75
yan752 楼6 年前

画布标识,传入 canvas 组件的 canvas-id。要不你就设置width,height为0或者不显示了

你忘记设置<canvas canvas-id="sku-bill-canvas"
了。而是设置 id="sku-bill-canvas"了?
ahu
ahu3 楼6 年前

https://github.com/qq674785876/wxa-comp-canvas-drag-master  给你个实例,有问题来一起讨论