大多數的小程序都會用的分享功能,如其實一些小遊戲,需要好友分數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);
}
}
},
想要獲得更多資料的 請微信搜索公衆號 【熱血科技】,關注一下即可。