1. Configure sharing-related information in the manifest.json file, including sharing titles, sharing pictures, etc.
code show as below:
{
"mp-weixin": {
"appid": "yourAppId",
"share": {
"title": "分享标题",
"imageUrl": "/static/share.png"
}
}
}
2. In the page that needs to trigger sharing, use the uni.navigateToMiniProgram() method to open the sharing page.
// 在当前页面中触发分享
uni.navigateToMiniProgram({
appId: '要分享到的小程序的AppID',
path: '要跳转到的页面路径',
extraData: {
// 可以携带一些额外的数据,在被分享的小程序中可以通过wx.getLaunchOptionsSync()获取
// 如:{from: 'uni-app'}
},
success(res) {
// 分享成功回调
console.log(res)
},
fail(err) {
// 分享失败回调
console.log(err)
}
})
3. In the shared applet, you can obtain the additional data carried during sharing through wx.getLaunchOptionsSync().
// 在被分享的小程序中获取额外数据
const launchOptions = wx.getLaunchOptionsSync()
console.log(launchOptions)