2023-09-22 uniapp canvas之ctx.draw没有回调 ==》ctx.draw(true, (() => {...})())

发布时间 2023-09-22 14:12:03作者: 哎呦你可棒棒了

try catch 无法捕获到错误,没有回调,没有反应,宛如石化一般,孤寂无边。

原本写法:

ctx.draw(false, () => {
  let a = setTimeout(async () => {
    const [err, res] = await uni.canvasToTempFilePath({
      canvasId: "canvas",
    });
    this.poster_img = res.tempFilePath;
    clearTimeout(a);
  }, 250);
});

把回调写成立即执行: