自定义组件中wx.drawCanvas没有效果,应该如何调用
发布于 5 年前 作者 yan91 7907 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

在自定义组件中wx.drawCanvas不起作用,也不报错。

  • 预期表现

在普通page中,此API接口可以正常调用。但是在自定义组件的methods中无法正常使用,期望wx.drawCanvas可以画出图

  • 复现路径
  • 提供一个最简复现 Demo

start: function(e){

this.setData({

oldX:e.touches[0].x,

oldY:e.touches[0].y

})

ctx.setStrokeStyle(this.data.color);

ctx.setLineWidth(this.data.width);

ctx.setLineCap(‘round’);

ctx.moveTo(e.touches[0].x, e.touches[0].y);

},

//移动

move: function(e){

ctx.moveTo(this.data.oldX,this.data.oldY);

ctx.lineTo(e.touches[0].x,e.touches[0].y);

ctx.stroke();

wx.drawCanvas({

canvasId: “paint”,

actions: ctx.getActions(),

reserve: true

})

this.setData({

oldX: e.touches[0].x,

oldY: e.touches[0].y

})

},

//触摸结束

end: function(e){

},

wxml中:

<canvas canvas-id=‘paint’ disable-scroll=‘true’ style=‘width:750rpx;height:800rpx’ bindtouchstart=‘start’ bindtouchmove=‘move’ bindtouchend=‘end’></canvas>

2 回复

@官方 遇到了一样的问题无法使用

wx.drawCanvas来绘制组件内的canvas 不能用drawCanvas的话就没办法回退了  希望解决这个问题

回到顶部