一、前置条件
- 定义一个按钮,设置
open-type="share"
<button class="forward" open-type="share" >转发</button>
二、事件触发
- 点击按钮会触发
onShareAppMessage事件
res中包含res.from及当前行等信息,通过res.from === 'button'条件判定来自分享按钮
- 必须有返回值,内含
标题title、跳转路径path、mpId用于配置微信小程序的AppId,
- 跳转路径可以携带参数
- mpId配置后其他用户才有权限访问
注意:onShareAppMessage事件与onLoad、methods、components等同级
onShareAppMessage(res) {
console.log('列表信息',res);
if (res.from === 'button') {
console.log(res.target)
}
return {
title: res.target.dataset.eventParams.ele.title,
path: 'pages/interpretAndDownload/interpretAndDownload?title=模版下载',
mpId: appid
}
},