1侣集、onShareAppMessage:監(jiān)聽用戶點(diǎn)擊右上角菜單的「轉(zhuǎn)發(fā)」按鈕時(shí)觸發(fā)的事件
2、添加分享按鈕及右上角的分享按鈕锅锨,文字及圖片內(nèi)容更改撒穷,時(shí)兩個(gè)轉(zhuǎn)發(fā)出去的內(nèi)容一樣
示例
1、小程序轉(zhuǎn)發(fā)的入口板惑,為圖片中的1,2 兩個(gè)位置
微信圖片_20200116154818.jpg
微信圖片_20200116154826.jpg
/**
* 用戶點(diǎn)擊右上角分享 .js文件
*/
onShareAppMessage: function (res) {
//轉(zhuǎn)發(fā)事件來源:button:頁面內(nèi)轉(zhuǎn)發(fā)按鈕橄镜;menu:右上角轉(zhuǎn)發(fā)菜單
if (res.from === 'button') {
console.log("來自頁面內(nèi)轉(zhuǎn)發(fā)按鈕");
console.log(res.target);
}
else {
console.log("來自右上角轉(zhuǎn)發(fā)菜單")
}
return {
title: '標(biāo)題',
imageUrl: "/resources/images/role/share.jpg",//轉(zhuǎn)發(fā)攜帶的圖片,可以是本地文件路徑、代碼包文件路徑或者網(wǎng)絡(luò)圖片路徑冯乘。支持PNG及JPG
path:"/pages/index/index",//當(dāng)前頁面 path 洽胶,必須是以 / 開頭的完整路徑
success: (res) => {
console.log("轉(zhuǎn)發(fā)成功", res);
},
fail: (res) => {
console.log("轉(zhuǎn)發(fā)失敗", res);
}
}
},
//.wxml文件
<view class="share-box">
<button class="share-btn" open-type="share">
<image src="/resources/images/index/share.png" class="share-img"></image>
</button>
</view>
//.wxss文件
.share-box{
position: fixed;
top:12%;
right: 6%;
}
.share-btn{
width: 120rpx;
height: 120rpx;
border-radius: 50%;
background: transparent;
border: red;
box-shadow: 0 0 25rpx #F81945;
}
.share-img{
width: 120rpx;
height: 120rpx;
}
button{
border: 0;
padding: 0;
margin: 0;
}