如何拿到onShareAppMessage接口正确的参数?
发布于 6 年前 作者 gyao 7617 次浏览 来自 问答

API:onShareAppMessage

基础库版本:2.11.3

问题,下面代码中,点击分享按钮后,onShareAppMessage接口接收到的参数res变成了Page的this 而不是文档中的from 和 target

😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡😡

// JS代码  
onShareAppMessage(res) {
    console.log(res, ">>>>>>")
    if (res.from === 'button') {
      // 这里的res绑定错误
      console.log(res.target)
    }
    return {};
  }

 // HTML代码
<button data-item="{{item}}" data-index="{{index}}" open-type="share" class="share-btn"></button>
2 回复

你好,是要转发后带参数过去吗?可先参考文档https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html#onShareAppMessage-Object-object

以及相关的示例。

把 res 打印出来看看

回到顶部