在做小程序分享時(shí),在上傳之前忘記測(cè)試分享功能,因?yàn)楫?dāng)時(shí)只使用了按鈕分享功能
按鈕分享代碼
<button class="class_guanzhu" data-src="這個(gè)是分享圖片地址" data-title="這個(gè)是分享標(biāo)題" open-type="share">發(fā)給好友</button>
<button data-src="這個(gè)是分享圖片地址" data-title="這個(gè)是分享標(biāo)題" open-type="share">發(fā)到朋友圈</button>
但是點(diǎn)擊小程序頂部的三點(diǎn)里面的分享
就發(fā)現(xiàn)發(fā)送給朋友與分享到朋友圈全是灰色不可以點(diǎn)擊的。
這是因?yàn)槟銢](méi)有設(shè)置相關(guān)的配置。需要設(shè)置當(dāng)前頁(yè)面的
以下的代碼是uni-app開(kāi)發(fā)使用的,不是小程序開(kāi)發(fā)工具使用的,請(qǐng)一定要注意。
//發(fā)送給朋友
onShareAppMessage(res) {
return {
title:this.sharedata.title,
path:this.sharedata.path,
imageUrl:this.sharedata.imageUrl,
desc:this.sharedata.desc,
content:this.sharedata.content,
success(res){
uni.showToast({
title:'分享成功'
})
},
fail(res){
uni.showToast({
title:'分享失敗',
icon:'none'
})
}
}
},
//uniapp微信小程序分享頁(yè)面到微信朋友圈
onShareTimeline(res) {
return {
title:this.sharedata.title,
query:'',
imageUrl:this.sharedata.imageurl,
success(res){
uni.showToast({
title:'分享成功'
})
},
fail(res){
uni.showToast({
title:'分享失敗',
icon:'none'
})
}
}
}
請(qǐng)點(diǎn)擊查看更多關(guān)于
微信小程序發(fā)送給朋友與分享到朋友圈的代碼
http://www.n6q2b.cn/new.asp?id=929
下以提供其它代碼參考:
onLoad(){
wx.showShareMenu({
withShareTicket:true,
//設(shè)置下方的Menus菜單,才能夠讓發(fā)送給朋友與分享到朋友圈兩個(gè)按鈕可以點(diǎn)擊
menus:["shareAppMessage","shareTimeline"]
})
},
//發(fā)送給朋友
onShareAppMessage(res) {
// 此處的distSource為分享者的部分信息,需要傳遞給其他人
let distSource = uni.getStorageSync('distSource');
if (distSource) {
return {
title: '深山工作室歡迎你',
type: 0,
path: '/pages/index/index',
summary: "",
imageUrl: "這個(gè)是分享圖片地址"
}
}
},
//分享到朋友圈
onShareTimeline(res) {
let distSource = uni.getStorageSync('distSource');
if (distSource) {
return {
title: '深山工作室歡迎你',
type: 0,
query: 'id=' + distSource, //這個(gè)是參數(shù)
summary: "",
imageUrl: "這個(gè)是分享圖片地址"
}
}
},
注意事項(xiàng)
分享給朋友圈功能是2020年7月份新增的功能,目前僅支持安卓,IOS不支持
目前是內(nèi)測(cè)階段,部分功能還是有問(wèn)題的,例如分享到朋友圈功能,其中的query參數(shù),這個(gè)參數(shù)在onLoad中是獲取不到的,也就是說(shuō)從此頁(yè)面分享出去的,其他人進(jìn)入此頁(yè)面是拿不到分享者的信息的。這樣就不能做分享者與用戶之間的關(guān)聯(lián)了。