php网站怎么变成小程序,如何在小程序页面内进行转发操作

本文详细介绍了在小程序中如何通过button组件设置open-type='share'来触发Page.onShareAppMessage事件,实现用户点击后的转发功能。内容包括两种情况:一是不带参数的转发,二是添加参数的转发。在添加参数时,展示了如何将用户信息或数据动态附加到转发路径中,并在onLoad的options中使用这些参数。此外,还强调了分享参数的设置对于转发效果的重要性。
摘要由CSDN通过智能技术生成

9c0b7857b75cfc3fee3e1b682b3c81f1.png

我们先来看看官方文档上的内容:

官方文档上说通过给 button 组件设置属性 open-type="share",可以在用户点击按钮后触发 Page.onShareAppMessage 事件,相关组件:button。

1b7389459bf3231032a0655ea52b20b6.png

aa08470723147028e1146b3e2d8e3521.png

第一种情况 点击小程序转发

f2699fd7b2bda8bf74c66248159df8cc.png

e5a6fa2bad93a46232ad3544688c6de4.png

不加入参数//转发

onShareAppMessage: function() {

let users = wx.getStorageSync('user');

if (res.from === 'button') {}

return {

title: '转发',

path: '/pages/index/index',

success: function(res) {}

}

}

加入参数//转发

onShareAppMessage: function() {

let users = wx.getStorageSync('user');

if (res.from === 'button') {}

return {

title: '转发',

path: '/pages/index/index?from_uid=' + users.id,

success: function(res) {}

}

}

第二种:分享

7b47be04259770efc3fd68d6233f6bc4.png

这个分享必须做成button 且加上 open-type="share"

不加入参数onShareAppMessage: function (res) {

if (res.from === 'button') {

}

return {

title: '转发',

path: '/pages/index/community/topic/topic',

success: function (res) {

console.log('成功', res)

}

}

}

加入参数//转发

onShareAppMessage: function (res) {

if (res.from === 'button') {

}

return {

title: '转发',

path: '/pages/index/community/topic/topic?jsonStr=' + this.data.list,

success: function (res) {

console.log('成功', res)

}

}

}

7dd0de5cb2f54994ea5afda19b258aa1.png

提醒:这里转发的参数要在onLoad 的options 运用

7af40580ab2861a7458e2915cd61d0b7.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值