微信小程序开发中onShareAppMessage分享:
分享按钮Html: 要把open-type设定为share,否则无法触发onShareAppMessage()
-
<view class='menu_1'>
-
<button class='share' id="shareBtn" open-type="share" hover-class="other-button-hover">
-
<image src='/images/menu1.png'></image>
-
<text>分享</text>
-
</button>
-
</view>
Js部分:
-
/**
-
* 用户点击右上角分享
-
* 分享文章页面
-
*/
-
onShareAppMessage: function (ops) {
-
if (ops.from === 'button') {
-
// 来自页面内转发按钮
-
console.log(ops.target)
-
console.log(this.data.id) //
-
//this.data.id 可以在Page({})里data中设定id
-
}
-
return {
-
title: '标签',
-
path: '/pages/detail/detail?id='+this.data.id, //这里设定都是以"/page"开头,并拼接好传递的参数
-
success: function (res) {
-
// 转发成功
-
console.log(res);
-
console.log("转发成功:" + JSON.stringify(res));
-
},
-
fail: function (res) {
-
// 转发失败
-
console.log("转发失败:" + JSON.stringify(res));
-
}
-
}
-
}