企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 微信自带分享 ### 分享到好友或群 第一种 ``` //右上角三点创建分享 wx.onMenuShareAppMessage({ title: '', // 分享标题 desc: '', // 分享描述 link: '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: '', // 分享图标 type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); ``` ### 第二种 通过按钮分享 ``` <button style="border: none;background:none;padding-left: 0;line-height: 1;margin: 0;" open-type="share"> 添加 open-type=“share” 就可以调用 js 里的函数 onShareAppMessage: function (ops) { if (ops.from === 'button') { // 来自页面内转发按钮 console.log(ops.target) } return { title: 'xx小程序', path: 'pages/index/index', //通过分享进入的页面路径 success: function (res) { // 转发成功 console.log("转发成功:" + JSON.stringify(res)); }, fail: function (res) { // 转发失败 console.log("转发失败:" + JSON.stringify(res)); } } }, ```