美文网首页
微信小程序--分享页面功能

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

作者: 七號7777 | 来源:发表于2019-10-28 17:31 被阅读0次

分享方法参考:

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

相关文章

网友评论

      本文标题:微信小程序--分享页面功能

      本文链接:https://www.haomeiwen.com/subject/ebsiyctx.html