微信小程序--分享页面功能

分享方法参考:

https://blog.csdn.net/stronglyh/article/details/97615610
https://www.jianshu.com/p/c7b1925cd3c1

一:给按钮绑定分享功能

<button open-type="share" class="cu-btn bg-green lg">邀请</button>

添加 open-type="share",表示分享

二:添加分享方法

默认截图是分享所在的功能页面,高宽5:4

// 此段代码需写到methods外,他是和 生命周期一级的
onShareAppMessage: function(res) {
    return { 
       title: 'xx小程序',
       path: 'pages/index/index?id=123&age=18',  // 路径,传递参数到指定页面。
       imageUrl:'../../imgs/xx.png' // 分享的封面图
       success: function (res) {
         // 转发成功
         console.log("转发成功:" + JSON.stringify(res));
       },
       fail: function (res) {
         // 转发失败
         console.log("转发失败:" + JSON.stringify(res));
       }
    }
}

分享按钮报错:Cannot read property 'apply' of null
解决:onShareAppMessage方法代码写到methods外,他是和 生命周期一级的
参考解决文档:https://blog.csdn.net/cow66/article/details/81660888

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容