特别汗颜,找了各种办法,都没有解决,最后发现,原来系统会自带一个空的onShareAppMessage函数,结果是被系统的空函数覆盖了。。。。。
JS函数如下:
/* 转发*/
onShareAppMessage: function (res) {
if (res.from === 'button') {
return {
title: '自定义转发标题',
path: '/pages/diCoupon/diCoupon',
}
}
},
页面代码如下:
记得在button上添加open-type=“share”
<button open-type="share" class="btn-red">分享好友助力 增加抽奖次数</button>
还可以在onload函数中屏蔽默认的分享功能。
onLoad: function (options) {
wx.hideShareMenu()
},
好了,微信小程序按钮分享的基本代码就是这样了。