1、在manifest.json文件中配置分享相關(guān)信息,包括分享標(biāo)題、分享圖片等。
代碼如下:
{
"mp-weixin": {
"appid": "yourAppId",
"share": {
"title": "分享標(biāo)題",
"imageUrl": "/static/share.png"
}
}
}
2、在需要觸發(fā)分享的頁面中,使用uni.navigateToMiniProgram()方法打開分享頁面。
// 在當(dāng)前頁面中觸發(fā)分享
uni.navigateToMiniProgram({
appId: '要分享到的小程序的AppID',
path: '要跳轉(zhuǎn)到的頁面路徑',
extraData: {
// 可以攜帶一些額外的數(shù)據(jù),在被分享的小程序中可以通過wx.getLaunchOptionsSync()獲取
// 如:{from: 'uni-app'}
},
success(res) {
// 分享成功回調(diào)
console.log(res)
},
fail(err) {
// 分享失敗回調(diào)
console.log(err)
}
})
?3、在被分享的小程序中,可以通過wx.getLaunchOptionsSync()獲取到分享時攜帶的額外數(shù)據(jù)。文章來源:http://www.zghlxwxcb.cn/news/detail-714403.html
// 在被分享的小程序中獲取額外數(shù)據(jù)
const launchOptions = wx.getLaunchOptionsSync()
console.log(launchOptions)
?文章來源地址http://www.zghlxwxcb.cn/news/detail-714403.html
到了這里,關(guān)于uni-app小程序中實現(xiàn)分享功能的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!