onShareAppMessage的图片路径可以是canva生成的路径吗?
发布于 5 年前 作者 songyan 10564 次浏览 来自 问答
async onShareAppMessage() {
    // console.log(this.listData.firstMessage);
    var _this = this;
    // var zfimg = "";
    const data = await  new Promise(function(resolve) {
      wx.canvasToTempFilePath({
        x: 0,
        y: 0,
        width: _this.rpx * 375,
        height: _this.canvasHeight1,
        destWidth: _this.rpx * 375 * _this.pixelRatio,
        destHeight: _this.canvasHeight1 * _this.pixelRatio,
        canvasId: "myCanvas1",
        success: function(res) {
          console.log(res.tempFilePath);
          // zfimg = res.tempFilePath;
          resolve(res.tempFilePath);
        }
      });
    });
    console.log(data);  //这里可以打印出图片路径
    return {
      title: _this.listData.firstMessage,
      path: "/pages/index/main?id=" + _this.listData.id,
      imageUrl: data,
      success: res => {
        console.log("转发成功", res);
      },
      fail: res => {
        console.log("转发失败", res);
      }
    };
  },

这个转发图片应该展示我用canvas生成的图片

1 回复

onShareAppMessage 不能是异步的哦,promise什么的,就当没有过一样。。

回到顶部