微信小程序分享好友
点击分享,弹出层选择“分享给微信好友”,点击‘“分享给微信好友”,直接调出选择好友聊天窗口。
如图:
微信小程序API:onShareAppMessage
定义 onShareAppMessage
函数,设置该页面的转发信息
1.在onLoad中配置wx.showShareMenu
onLoad: function (e) {wx.showShareMenu({// 要求小程序返回分享目标信息withShareTicket: true}); },
2.配置onShareAppMessage
/* 转发*/onShareAppMessage: function (ops) {if (ops.from === 'button') {// 来自页面内转发按钮console.log(ops.target)}return {title: '转发dom',path: `pages/index/index`,success: function (res) {// 转发成功console.log("转发成功:" + JSON.stringify(res));var shareTickets = res.shareTickets;},fail: function (res) {// 转发失败console.log("转发失败:" + JSON.stringify(res));}}}
3.页面分享按钮
<view class="container"><view class="userinfo"><button open-type="share">分享好友</button></view>
</view>
注意
button一定要设置open-type="share"否则不起作用。
欢迎和我交流前端方面的知识,一起学习与进步。
希望本文对你有帮助哟!