微信小程序全局分享好友、朋友圈
·
1.在 app.js 中
// app.js
App({
onLaunch() {
this.overShare();
},
// 全局分享
overShare: function () {
//间接实现全局设置分享内容
wx.onAppRoute(function (res) {
//获取加载的页面
let pages = getCurrentPages(),
//获取当前页面的对象
view = pages[pages.length - 1],
data;
if (view) {
data = view.data;
if (!data.isOverShare) {
data.isOverShare = true;
//分享给好友
view.onShareAppMessage = function () {
return {
title: "陈陈小商铺",
path: "/pages/index/index", //分享页面地址
imageUrl: "/static/images/share.png",
};
};
//分享朋友圈
view.onShareTimeline = function () {
return {
title: "陈陈小商铺",
imageUrl: "/static/images/share.png",
// 具体其他参数详见小程序开放平台
};
};
}
}
});
},
});
2.给页面添加分享权限
//分享给好友
onShareAppMessage() {},
// 分享到朋友圈
onShareTimeline() {},
提示:
给想要分享的页面写上就有权限,内容为空即可,内容在app.js中配置,没有的话即为禁止分享
更多推荐
所有评论(0)