一、利用小程序右上角自带的分享
1、只需要一句js代码即可
//点击小程序右上角即可转发分享本页面onShareAppMessage: function() {}
分享按钮:
分享的效果:
二、自己写一个自定义按钮:
1、自定义一般利用button按钮来实现的,官方文档给的解决方案是button里面添加一个open-type=‘share
’wxml
<button open-type='share'>//button按钮形状<image scr='url'></image></button>
js
//点击小程序右上角即可转发分享本页面onShareAppMessage: function() {}
2、自定义分享内容的 js
//点击小程序右上角即可转发分享本页面onShareAppMessage: function(res) {if (res.from === 'button') {// 来自页面内转发按钮console.log(res.target)}return {title: '转发23456',path: 'pages/index/index',imageUrl: '',success: function (shareTickets) {console.info(shareTickets + '成功');// 转发成功},fail: function (res) {console.log(res + '失败');// 转发失败},complete: function (res) {// 不管成功失败都会执行}}}
三、分享到朋友圈
1、分享到朋友圈,只需要添加这句话即可
// onShareTimeline(){var self = this;var shareObj = {title: 'xxxxx',imageUrl: "https://xxxxx/aaaa.png",};return shareObj;},