大多数的小程序都会用的分享功能,如其实一些小游戏,需要好友分数pk之类的。下面就来说一下这个能弄如何实现。
首先来看一下文档上的组件button
button组件提供了open-type属性,看看他有什么值
这个就是用button做分享按钮必须要加的属性,下面看一下具体的代码。
<button open-type='share' >炫耀战绩</button>
onShareAppMessage: function (res) { if (res.from === 'button') { // 来自页面内转发按钮 console.log(res.target) } return { title: '自定义转发标题', path: '/page/user?id=123', success: function (res) { // 转发成功 console.log(res); }, fail: function (res) { // 转发失败 console.log(res); } } },