微信小程序開發(fā)過程中,我們需要把小程序設(shè)置為用戶可以自己轉(zhuǎn)發(fā)給好友,也可以把小程序分享到朋友圈,需要按照以下步驟來設(shè)置。
1. 在page中需要定義方法
?? ??? ??? ?onShareAppMessage(res) {
?? ??? ??? ? ? ?// return custom share data when user share.
?? ??? ??? ??? ?console.log("分享了")
?? ??? ??? ??? ? const promise = new Promise(resolve => {
?? ??? ??? ??? ??? ? ?setTimeout(() => {
?? ??? ??? ??? ??? ??? ?resolve({
?? ??? ??? ??? ??? ??? ? ? title: '自己定義的標(biāo)題',
?? ??? ??? ??? ??? ??? ? ?path: '/pages/index/index',
?? ??? ??? ??? ??? ??? ? ?imageUrl: '/static/自己定義的圖片路徑'
?? ??? ??? ??? ??? ??? ?})
?? ??? ??? ??? ??? ? ?}, 2000)
?? ??? ??? ??? ??? ?})
?? ??? ??? ??? ??? ?return {
?? ??? ??? ??? ??? ? ?title: '自己定義的標(biāo)題',
?? ??? ??? ??? ??? ? ?path: '/pages/index/index',
?? ??? ??? ??? ??? ? ?imageUrl: '/static/自己定義的圖片路徑',
?? ??? ??? ??? ??? ? ?promise?
?? ??? ??? ??? ??? ?}
?? ??? ??? ?},
此時(shí)微信小程序就可以轉(zhuǎn)發(fā)給好友了,如果需要設(shè)置為可以分享到朋友圈,還需要再完成上一步的基礎(chǔ)上再進(jìn)行下一步。
2. 在page中定義以下方法
?? ??? ??? ?onShareTimeline(res){
?? ??? ??? ??? ?console.log("分享朋友圈")
?? ??? ??? ??? ?console.log(res)
?? ??? ??? ?},
此時(shí)就可以將小程序準(zhǔn)發(fā)給好友,也可以分享到朋友圈。
除了在右上角點(diǎn)開設(shè)置進(jìn)行分享和轉(zhuǎn)發(fā)外,還可以在頁面添加按鈕,讓用戶轉(zhuǎn)發(fā),按鈕如下:
?? ??? ??? ??? ?<button class="mini-btn" open-type="share">
?? ??? ??? ??? ??? ?<uni-icons type="redo" size="20" color="#103667"></uni-icons>分享
?? ??? ??? ??? ?</button>
,其中?? <uni-icons type="redo" size="20" color="#103667"></uni-icons>? 也可以不要,這就是一個(gè)轉(zhuǎn)發(fā)的圖標(biāo)。
如下可以試用看效果
文章來源:http://www.zghlxwxcb.cn/news/detail-497087.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-497087.html
到了這里,關(guān)于微信小程序開發(fā),設(shè)置小程序?yàn)榭赊D(zhuǎn)發(fā)可分享朋友圈的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!