自定义组件里调用wx.canvasToTempFilePath失败

发布于 8 年前作者 cmo2404 次浏览最后编辑 8 年前来自 ask

我想反馈一个 问题:

自定义组件里定义

<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 回复
wwang
wwang1 楼6 年前

谢谢你啊

mingfu
mingfu2 楼6 年前

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)

},

panyang
panyang3 楼6 年前

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

wx.canvasToTempFilePath

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

li83
li834 楼6 年前

谢谢

junpan
junpan5 楼6 年前

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

qwan
qwan6 楼6 年前

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

liaojun
liaojun7 楼6 年前

解决了么?

fangtang
fangtang8 楼6 年前

解决了

liulei
liulei9 楼6 年前

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

aqian
aqian10 楼6 年前

加了也不行