无法在image标签里显示的代码

    1. ctx.drawImage("/" + resp.path, 175, imgH - 370, 250, 250);
    2. ctx.draw();
    3. wx.canvasToTempFilePath({
    4. canvasId: "myCanvas",
    5. success: res => {
    6. console.log("合成的带有小程序码的图片success》》》", res);
    7. let tempFilePath = res.tempFilePath;
    8. this.resultImg = tempFilePath; // image标签获取图片路径
    9. },
    10. fail: e => {
    11. console.log(e);
    12. }
    13. });

    无法显示的原因:异步执行
    解决办法

    1. ctx.drawImage("/" + resp.path, 175, imgH - 370, 250, 250);
    2. ctx.draw(false, () => {
    3. wx.canvasToTempFilePath({
    4. canvasId: "myCanvas",
    5. success: res => {
    6. console.log("合成的带有小程序码的图片success》》》", res);
    7. let tempFilePath = res.tempFilePath;
    8. this.resultImg = tempFilePath;
    9. },
    10. fail: e => {
    11. console.log(e);
    12. }
    13. });
    14. });