分享方法參考:
https://blog.csdn.net/stronglyh/article/details/97615610
http://www.itdecent.cn/p/c7b1925cd3c1
一:給按鈕綁定分享功能
<button open-type="share" class="cu-btn bg-green lg">邀請(qǐng)</button>
添加 open-type="share",表示分享
二:添加分享方法
默認(rèn)截圖是分享所在的功能頁(yè)面,高寬5:4
// 此段代碼需寫(xiě)到methods外,他是和 生命周期一級(jí)的
onShareAppMessage: function(res) {
return {
title: 'xx小程序',
path: 'pages/index/index?id=123&age=18', // 路徑,傳遞參數(shù)到指定頁(yè)面。
imageUrl:'../../imgs/xx.png' // 分享的封面圖
success: function (res) {
// 轉(zhuǎn)發(fā)成功
console.log("轉(zhuǎn)發(fā)成功:" + JSON.stringify(res));
},
fail: function (res) {
// 轉(zhuǎn)發(fā)失敗
console.log("轉(zhuǎn)發(fā)失敗:" + JSON.stringify(res));
}
}
}
分享按鈕報(bào)錯(cuò):Cannot read property 'apply' of null
解決:onShareAppMessage方法代碼寫(xiě)到methods外,他是和 生命周期一級(jí)的
參考解決文檔:https://blog.csdn.net/cow66/article/details/81660888