小程序商品分享给朋友和分享朋友圈踩坑

  1. 已经写了onShareAppMessage 和 onShareTimeline,但是分享朋友圈按钮依旧灰色不可点击:
    解决:需要在onload 方法里调用 wx.showShareMenu让分享朋友圈按钮显示
    注意:这里有个坑:
    uni.showShareMenu 里面没有封装 menus 字段,所以需要调用原生的wx.showShareMenu方法,然后还有个问题,eslint 会报 wx is not defined ,这个时候需要在 .eslintrc.js文件中的globals 里面设置下wx为全局变量!!!
  2. 可以分享朋友圈了,但是自定义的标题和图片没有生效,甚至没有进入执行我们定义的 onShareTimeline 方法
    解决:我参考的这个 https://ask.dcloud.net.cn/question/101160
    修改的node_module 包里的文件,再进行打包上传,不过这个要注意再重新npm install 的时候需要重新修改,不能忘记!!!

相关官方文档:
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
https://developers.weixin.qq.com/miniprogram/dev/api/share/wx.showShareMenu.html

onLoad(options) {
    this.productCode = options.productCode;
    this.getproductInfo();
    wx.showShareMenu({
      withShareTicket: true,
      menus: ["shareAppMessage", "shareTimeline"],
    });
  }

  onShareAppMessage() {
    return {
      title: this.productInfo.productName,
      imageUrl: this.productImage[0],
      path: PATH_PDP + "?productCode=" + this.productCode
    };
  }
  onShareTimeline() {
    console.log("onShareTimeline", {
      title: this.productInfo.productName,
      query: "productCode=" + this.productCode,
      imageUrl: this.productImage[0],
    });
    return {
      title: this.productInfo.productName,
      query: "productCode=" + this.productCode,
      imageUrl: this.productImage[0]
    };
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值