uni-app 微信小程序 canvasToTempFilePath一直报错 生成图片失败
uni-app 微信小程序 canvasToTempFilePath一直报错 生成图片失败
示例代码:
uni.canvasToTempFilePath({
x: 0,
y: 0,
width: canvasWidth.value,
height: canvasHeight.value,
canvas: canvas.value,
fileType: 'png',
quality: 1,
success: function (res) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success(result) {
uni.hideLoading()
uni.showToast({
title: '图片已保存到相册',
icon: 'none',
duration: 3000,
})
},
fail(error) {
uni.hideLoading()
if (error.errMsg.indexOf('cancel') === -1) {
uni.showToast({
title: '请同意存储权限哦',
icon: 'none',
duration: 2000,
})
}
}
})
},
fail: function (err) {
uni.hideLoading()
console.log(err)
}
})
操作步骤:
画布生成图片
预期结果:
画布生成图片
实际结果:
画布生成图片
bug描述:
如何,报错canvasToTempFilePath:fail Cannot read property ‘width’ of undefined。我确认代码没问题
同步一下,确实是个问题,vue3用 ref 定义canvas就会报这个错,直接 let canvas = null;就可以了,希望遇到的朋友能看到
项目信息 | 描述 |
---|---|
产品分类 | uniapp/小程序/微信 |
PC开发环境操作系统 | Windows |
PC开发环境操作系统版本号 | Windows11 |
HBuilderX类型 | 正式 |
HBuilderX版本号 | 4.25 |
第三方开发者工具版本号 | 1.06.2405020 |
基础库版本号 | 3.5.5 |
项目创建方式 | HBuilderX |
更多关于uni-app 微信小程序 canvasToTempFilePath一直报错 生成图片失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html
5 回复
你好,你是vue2还是vue3出现的这个问题
更多关于uni-app 微信小程序 canvasToTempFilePath一直报错 生成图片失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html
vue3呢
同步一下,确实是个问题,vue3用 ref 定义canvas就会报这个错,直接 let canvas = null;就可以了,希望遇到的朋友能看到
这里测试的是正常的
vue3 报的错