- 已经写了onShareAppMessage 和 onShareTimeline,但是分享朋友圈按钮依旧灰色不可点击:
解决:需要在onload 方法里调用 wx.showShareMenu让分享朋友圈按钮显示
注意:这里有个坑:
uni.showShareMenu 里面没有封装 menus 字段,所以需要调用原生的wx.showShareMenu方法,然后还有个问题,eslint 会报 wx is not defined ,这个时候需要在 .eslintrc.js文件中的globals 里面设置下wx为全局变量!!! - 可以分享朋友圈了,但是自定义的标题和图片没有生效,甚至没有进入执行我们定义的 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]
};
}