wechat-小程序-分享

xiaoxiao2025-04-21  17


title: wechat-小程序-分享 categories: Wechat tags: [wechat, 分享, 小程序] date: 2018-10-29 14:13:18 comments: false

参考文档

获取更多转发信息 - https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html

onShareAppMessage - https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/page.html#onshareappmessageobject


触发分享的两种方式

右上角菜单

页面 自定义按钮

只需要在 button 标签中加入 open-type="share"

<view class="btn-area"> <button type="primary" open-type="share">分享</button> </view>

这两种方式都会触犯分享, 并调用 Page.onShareAppMessage 方法


分享传递参数

onShareAppMessage 定义相关参数

onShareAppMessage: function (options) { if (options.from === 'button') { // 来自 页面自定义按钮, 可以获取到按钮相关参数 console.log(options.target) } return { title: '--- aaa: 自定义转发标题', imageUrl: 'http://p7kuppz6y.bkt.clouddn.com/testShare.jpg', // 分享图(比例是 5:4), 不定义的话默认使用当前界面的截图. path: '/pages/show/show?id=123&name=hello', // 分享出去后, 别人点击后跳转的页面及相关参数传递过去. 这里只能使用绝对路径. success: (res) => { console.log("--- success, res:", res) }, fail: (res) => { console.log("--- fail, res:", res) } } },

测试

a用 户分享给 b用户, b用户点击后会 直接跳转到 /pages/show/show 界面 并在 Page.onLoad 方法中可以获取到参数 id 和 name

onLoad: function (options) { gLog("--- show onLoad", options) },

转载请注明原文地址: https://www.6miu.com/read-5028754.html

最新回复(0)