想实现canvas do,undo的效果,发现canvas.toDataURL is not a function?
do(e){
var that=this
wx.createSelectorQuery().select('#canvas'+that.data.list.genre).fields({ node: true, size: true }).exec(
(res)=>{
const canvas = res[0].node
that.data.canvas.history=[]
that.data.canvas.history.push(canvas.toDataURL('image/png',1))
}
)
}
离屏canvas 貌似不支持这个方法?
也遇到这个问题了,基础库 2.11.0 才开始支持这个API
看下canvas是否是canvas实例。
this.createSelectorQuery().in(this).select('#test')
.fields({ node: true, size: true })
.exec((rect) => {
const node = rect[0].node;
const ctx = node.getContext('2d');
console.log(node);
ctx.textBaseline = 'top';
ctx.font = '30px sans-serif';
ctx.fillText('test', 0, 0);
this.setData({
imgData: node.toDataURL('image/png',1),
});
});
https://developers.weixin.qq.com/miniprogram/dev/api/canvas/Canvas.toDataURL.html