收藏
回答

急急急!求解答!自定义组件中调用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 个回答

登录 后发表内容
问题标签