分享给朋友
微信小程序分享给朋友比较简单,只需要在要分享的页面中设置onShareAppMessage即可。
只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮
监听用户点击页面内转发按钮(button 组件 open-type="share")或右上角菜单“转发”按钮的行为,并自定义转发内容。
<button open-type="share">分享按钮</button>
onShareAppMessage如果带了参数,参数中的from会指明是从哪里触发的,从按钮触发from='button',从右上角菜单中触发from='menu'
onShareAppMessage: function (res) { //console.log('onShareAppMessage',res); return { title: '自定义标题', path: '/pages/index/index?userId='+Constant.userId+'&share=true', } }, //onShareAppMessage {from: "button", target: {…}}
支持自定义标题,自定义路径和自定义图片