- I have written onShareAppMessage and onShareTimeline, but the Share Moments button is still gray and unclickable:
Solution : You need to call wx.showShareMenu in the onload method to display the Share Moments button.
Note : There is a pit here:
uni.showShareMenu does not encapsulate the menus field. So you need to call the native wx .showShareMenu method, and then there is a problem. eslint will report wx is not defined . At this time, you need to set wx as a global variable in the globals in the .eslintrc.js file! ! ! - You can share the circle of friends, but the customized titles and pictures do not take effect, and it does not even enter the onShareTimeline method we defined.
Solution : I refer to this https://ask.dcloud.net.cn/question/101160
modified node_module package The files in the package are then packaged and uploaded. However, please note that this needs to be modified again when npm install is re-installed. Don’t forget it! ! !
Relevant official documents:
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]
};
}