收藏
回答

请问如何动态调用wx.onShareAppMessage()?

/**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    console.log("aaaaa")
    return publicMethods.shareAppMessage()
  },
  onShareTimeline() {
    console.log("sdfasdfasdf")
    return publicMethods.shareAppMessage()
  },
  handleLongPress() {
    // 保存 canvas 图片并显示操作菜单
    wx.canvasToTempFilePath({
      canvasId: 'myCanvas',
      success: (res) => {
        console.log('canvasToTempFilePath success:', res.tempFilePath);
        this.setData({
          canvasImg: res.tempFilePath,
        });
        wx.showActionSheet({
          itemList: ['保存图片''发送给好友''分享到朋友圈'],
          success: (res) => {
            console.log("res", res)
            switch (res.tapIndex) {
              case 0:
                // 保存图片
                this.saveImageToPhotosAlbum();
                break;
              case 1:
                // 发送给好友
                this.onShareAppMessage()
                break;
              case 2:
                // 分享到朋友圈
                this.onShareTimeline()
                break;
              default:
                break;
            }
          },
        });
      },
      fail: (res) => {
        console.log('canvasToTempFilePath fail:', res);
      },
    });
  },

在一个canvas上长按执行上面的三个事件,console.log("aaaaa") 这个打印有执行,但是转发好友和朋友圈都没有弹出分享框,
回答关注问题邀请回答
收藏

1 个回答

  • 悟
    2023-03-07
    path后接动态参数
    onShareAppMessage() {
        return {
          title: '自定义转发标题',
          path: '/page/user?id=123',
          promise 
        }
      }
    


    2023-03-07
    有用
    回复
登录 后发表内容