关于uniapp x 使用了 uni.canvasToTempFilePath方法后无法得到路径的问题,通过一段时间的踩坑,终于解决了。
首先我们使用uniapp x的时候,大概率是使用uni.createCanvasContextAsync 方法,然后画完之后,就需要导出图片,这时候如果按照 uni.canvasToTempFilePath 方法去导出,我遇到了 “canvasToTempFilePath:fail fail canvas is empty” 报错,可我明明是使用了官方的方法去传入变量啊。下列就是代码实现过程:
uni.createSelectorQuery().select('#lastCanvas').fields({
node:true
},(res)=>{
console.log(res);
}).exec((ret)=>{
console.log(ret);
uni.canvasToTempFilePath({
canvasId:"lastCanvas",
canvas:ret[0].node,
success:function(res){
console.log(res)
},
fail:function(err){
console.log(err)
}
},this);
});
我们先去找到元素的node,然后把它塞进去canvas, 就能拿到我们的导出图片了。
真的是又又又踩坑了。
1 个评论
要回复文章请先登录或注册
b***@163.com