注意:更多注意事项见uni-app文档
结果展示:
先展示:
实现分享好友
实现分享朋友圈
注意:这两个方法和页面生命周期onLoad()同一级
详见代码:
onLoad(option) {
this.setPaintOrgIdData(option);
this.getProductData(option);
},
// 微信小程序右上角分享
onShareAppMessage() {
return this.getShareData();
},
// 转发至朋友圈
onShareTimeline() {
return this.getShareData("timeline");
},methods:{
getShareData(type) {
let title = "分享标题";
// 判断本地是否存在ID---------(这个不重要,目的是为了获取 path)
let paintOrgId = uni.getStorageSync("paintOrgId");
let path = `/pages/index/index`;
if (paintOrgId) {
path = `${path}?id=${paintOrgId}`;
}
let imageUrl = "../../static/images/public/ic_unified_share.png";
if (type == "timeline") {
return {
title,
imageUrl,
query: path,
};
}
return {
title,
imageUrl,
path,
};
},}
模仿上面的代码就能实现