自定义组件里调用wx.canvasToTempFilePath失败
发布于 6 年前 作者 cmo 2266 次浏览 来自 问答

我想反馈一个 问题:

自定义组件里定义

<canvas  class=“papercanvas”  canvas-id=“PaperCanvas” id=“PaperCanvas”  bindtouchstart=“touchStart” bindtouchmove=“touchMove” bindtouchend=“touchEnd” bindtouchcancel=“touchCancel” binderror=“canvasError” disable-scroll=“true”></canvas>

绘图区域可以正常写字,调用微信API:

wx.canvasToTempFilePath({

canvasId: ‘PaperCanvas’,

success: function (res) {

console.log(res.tempFilePath);

},

fail: function (res) {

console.log(res);

}

结果:

errMsg:“canvasToTempFilePath:fail canvas is empty

但是在普通页面调用此API就不会报错。

10 回复

谢谢你啊

getHandWritingPng:function(){

var paperThis = this;

const app=getApp();

wx.canvasToTempFilePath({

canvasId: ‘PaperCanvas’,

success: function (res) {

console.log(“成功获取图片”+res.tempFilePath);

app.data.handwritingpath = res.tempFilePath

return res.tempFilePath

},

fail: function (res) {

console.log(res);

return ‘’

}

}, paperThis)

},

怎么实现的,能贴一下代码么?我在组件里用

wx.canvasToTempFilePath

只能调用一次,之后再调用,不能触发

在自定义组件里使用<canvas/> ,wx.canvasToTempFilePath(obj,which),这里的第二个参数必须要填,就是当前component实例。

传this不管用的话,尝试一下将this替换为组件元素,通过this.selectComponent获取

解决了么?

那你的检查代码其他地方,我这边可以用。

加了也不行

回到顶部