this.$nextTick(() => {
const ctx = uni.createCanvasContext("screenshotCanvas");
ctx.fillStyle = '#007aff';
// 绘制一个矩形,参数分别为:左上角x坐标, 左上角y坐标, 宽度, 高度
ctx.fillRect(0, 0, 200, 100);
ctx.save();
ctx.fillStyle = '#000000';
ctx.fillText('测试数据', 100, 50);
ctx.stroke();
console.log("ctx---", ctx);
// 在try中页不报错
try {
/**
- 两种方式
-
ctx.draw 在页面中都没有效果
*/
// 这里没有回调
ctx.draw(true, () => {
// 到这里的代码就没有触发了
console.log("ctx---", ctx);
setTimeout(() => {
console.log("ctx===", ctx);
}, 50)
})/**
- 下面这段draw的回调函数是触发了,但是uni.canvasToTempFilePath又没有触发
-
应该是上一步draw,没有绘制成功。
*/
// ctx.draw(true, (() => {
// console.log("res---", res);
// setTimeout(() => {
// uni.canvasToTempFilePath({
// canvasId: "screenshotCanvas",
// fileType: 'png',
// success: (res) => {
// console.log('成功:', res.tempFilePath);
// },
// fail: (err) => {
// console.error('失败:', err); // 输出具体错误信息
// },
// complete: () => {
// console.log('调用完成'); // 确认 API 是否被触发
// }
// })
// }, 50)
// })());
}catch(eror){
console.log("eror---", eror)
}})
0 个回复